这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2399
考察输入的题目,如何输入一行(包括空格)?具体见:
http://www.wutianqi.com/?p=1181
以下是AC代码:
#include
#include
#include
using namespace std;
string str;
int main()
{
while(getline(cin, str))
{
bool flag = 1;
int cnt = 0;
int num = 0;
int len = str.size();
for(int i=0; i<len; ++i)
{
if(str[i] == ' ')
;
else if(str[i] == 'A')
{
++num;
cnt += 4;
}
else if(str[i] == 'B')
{
++num;
cnt += 3;
}
else if(str[i] == 'C')
{
++num;
cnt += 2;
}
else if(str[i] == 'D')
{
++num;
cnt += 1;
}
else if(str[i] == 'F')
{
++num;
cnt += 0;
}
else
{
flag = 0;
cout << "Unknown letter grade in input\n";
break;
}
}
if(flag)
{
printf("%.2lf\n", cnt*1.0/num);
}
}
}