2004 成绩转换,把百分制转换成等级
#include <iostream>
using namespace std;
int main()
{
int t;
while(cin >> t)
{
if(t<0 || t>100)
cout << "Score is error!" << endl;
else if(t>=90 && t<=100)
cout << "A" << endl;
else if(t>=80 && t<=89)
cout << "B" << endl;
else if(t>=70 && t<=79)
cout << "C" << endl;
else if(t>=60 && t<=69)
cout << "D" << endl;
else
cout << "E" << endl;
}
return 0;
}
2005 第几天
#include <iostream>
using namespace std;
int main()
{
int y,m,d;
int m1[11] = {31,28,31,30,31,30,31,31,30,31,30};
int m2[11] = {31,29,31,30,31,30,31,31,30,31,30};
while(cin >> y)
{
int s=0;
cin.ignore();//忽略斜杠
cin >> m;
cin.ignore();
cin >> d;
if((y%400==0) || (y%4==0)&&(y%100!=0))//闰年
{
for(int i=0;i<m-1;i++)
{
s += m2[i];
}
s += d;
}
else
{
for(int i=0;i<m-1;i++)
{
s += m1[i];
}
s += d;
}
cout << s << endl;
}
return 0;
}
注意s的定义位置,每一轮s都需要重新计算。
2006 求奇数的乘积
#include <iostream>
using namespace std;
int main()
{
int n,a;
int result = 1;
while(cin >> n)
{
while(n--)
{
cin >> a;
if(a%2==1) result *= a;
}
cout << result << endl;
result = 1;
}
return 0;
}