Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
N次WA提交了N遍才PASS也算汗颜了。。。 后来才发现原来是因为如果输入#结尾我的代码会输出0 所以加了一个FLAG判断 以下附上代码: ==================================================================== #include "stdlib.h" #include "stdio.h" #include "string.h" #define MAX_BUFF_SIZE 255 #define TRUE 1 int main(void){ char input[MAX_BUFF_SIZE + 1]; do{ int len; fgets(input,MAX_BUFF_SIZE + 1,stdin); len = strlen(input); input[len - 1] = '\0'; if(input[0] == '#'){ break; } else{ int i = 0,result = 0; int flag = -1; for(;i<len;i++){ char ch = input[i]; if(ch >= 'A' && ch <= 'Z'){ result += (i + 1)*(ch - 'A' + 1); flag = 0; } else if(ch == ' ') flag = 0; } if(0 == flag) printf("%d\n",result); } } while(TRUE); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator