好久没登陆 Topcoder Arena 了,上一次登陆是五月份,当时随ACM 协会去南师大比赛了一次,当时菜极了,什么都不会,连 iterator、vector都不会,看着简单的杂题和01背包问题,只能眼巴巴提交不成功0分归来……当时连挑刺都不会呀……
今没事干,安装了 Arena ,做了一题练习题2001-R1-prob01-250,250分的,却值得了 76.3……为什么呢?
#include <iostream>
#include <string>
using namespace std;
class HowEasy{
public:
int pointVal(string problemStatement)
{
int len, chars;
int lengthsSum = 0, wordsNum = 0;
int i = 0, level;
problemStatement += ' ';
while(i < problemStatement.size())
{
len = chars = 0;
while(i < problemStatement.size())
{
if (problemStatement[i] == ' ')
{
if (chars < 2)
{
lengthsSum += len;
break;
}
}
if ((problemStatement[i] >= 'a' && problemStatement[i] <= 'z') ||
(problemStatement[i] >= 'A' && problemStatement[i] <= 'Z'))
{
len++;
}
else
{
chars++;
}
i++;
}
i++;
wordsNum++;
}
switch(lengthsSum / wordsNum)
{
case 0:
case 1:
case 2: level = 1; break;
case 3:
case 4:
case 5: level = 2; break;
default: level = 4; break;
}
return level * 250;
}
};