A+B Problem 遇到问题(悬赏测试)

jxtxzzw edited 5 年,1 月前

本地调试没有问题,样例得到正确结果,但是提交的时候 WA,感觉是那个 for 循环的问题,已经排除了被除数是 0 的问题,可能有其他特殊情况没有考虑?

悬赏测试
-------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char alphabet[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};

int main()
{
    int cas;
    scanf("%d",&cas);
    for (int t=0;t<cas;t++){
		int a=0,b=0,ans=0;
		int flag=0;
		char s[10]={0};
		char ch;
		do {
			scanf("%s",s);
			if (s[0]!='+' && s[0]!='='){
				int tmp;
				for (int i=0;i<10;i++){
					if (strcmp(s,alphabet[i])==0){
						tmp=i;
					}
				}
				if (flag==0){
					a = a*10 + tmp;
				} else {
					b = b*10 + tmp;
				}
			} else if (s[0]=='+')
				flag=1;
			} else {
				ans = a+b;
				printf("case #%d:\n%d\n",t,ans);
			}
		} while ((ch=getchar()) && ch!='\n');
    }
    return 0;
}

Comments