新人求救
pascal吧
全部回复
仅看楼主
level 3
李幸蓉10 楼主
第二题:信息技术期末考试结束了,老师在键盘上输入初一年级某个班的信息技术成绩,当输入“*”时代表全部学生的成绩输入完毕。现在请你编程,可以统计这个班的人数,这个个班的平均分。(保留两位小数)
样例输入:
98 97 99 *
样例输出:
3
2016年01月24日 15点01分 1
level 9
就是找到学生个数有点小难
不过给了你“*”,否则还要找回车
2016年02月01日 02点02分 5
level 2
代码如下:
#include<iostream>
#include<strstream>
using namespace std;
int main()
{
char str[50]={' '};
cin.get(str,50,'*');
int count=1;
for(int i=0;i<50;i++) if(str[i]==' ')count++;
float score[20]={0},sum=0;
istrstream in(str);
for(int i=1;i<=count;i++){
in>>score[i];
sum+=score[i];
}
cout<<count<<" "<<sum/count<<endl;
return 0;
}
2016年02月01日 13点02分 7
1