发布时间:2023-11-05 12:26来源:www.sf1369.com作者:宇宇
很明显,第一个是累和
第二个错误在
for(j=0;j<s;j++){
s=0;
/*
A B C D F
2.00
B F F C C A
1.83
D C E F
Unknown
^Z
Press any key to continue
*/
#include int main(){ int i,flag,d; char str[50]; float sum; while(gets(str) != NULL) { i = 0; d = 0; sum = 0; flag = 0; while(str[i] != '\0') { switch(str[i]) { case 'A' : sum += 4; break; case 'B' : sum += 3; break; case 'C' : sum += 2; break; case 'D' : sum += 1; break; case 'F' : break; case ' ' : --d; break; default : flag = 1; printf(Unknown\n); break; } if(flag == 1) break; d++; i++; } if(flag == 0) { if(d != 0) printf(%.2f\n,sum/d); else printf(0.00\n); } } return 0; }
#include#include void main(){ float sum=0,ave[100]={-1.0}; int amount=0,j=0; char s[100]; while(1){ gets(s); for(int i=0;i switch(s[i]){ case 'A': sum+=4; amount+=1; break; case 'B': sum+=3; amount+=1; break; case 'C': sum+=2; amount+=1; break; case 'D': sum+=1; amount+=1; break; case 'F': sum+=0; amount+=1; break; case ' ': break; default: for(int k=0;k printf(%.2f\n,ave[k]); } printf(Unknown\n); return; } } ave[j]=sum/amount; j++; sum=0; amount=0; } }