ZOJ 3654 Letty's Math Class

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3654

首先必须说自己今天很2。。。。。

一个数据范围搞了那么久,还有就是自己对表达式的理解上也有问题。。。。

View Code
 1 #include <stdio.h>
 2 #include <string.h>
 3 #define maxn 2012
 4 long long ans;
 5 char str[maxn];
 6 
 7 void cal(char str[])
 8 {
 9     int i,j,len,f,mark;
10     long long temp,k;
11     len=strlen(str);
12     str[len]='+';
13     str[++len]='\0';
14     ans=0;
15     f=1;
16     mark=-1;
17     for(i=0;i<len;i++)
18     if(str[i]=='-'||str[i]=='+')
19     {
20         k=1;
21         temp=0;
22         for(j=i-1;j>mark;j--)
23         {
24             temp+=k*(str[j]-'0');
25             k*=10;
26         }
27         if(str[mark]=='-')
28             temp=-temp;
29         ans+=temp;
30         mark=i;
31     }
32 }
33 
34 int main()
35 {
36     long long a,b;
37     while(gets(str))
38     {
39         scanf("%lld%lld",&a,&b);
40         getchar();
41         if(a==9)
42             printf("A\n");
43         else if(b==9)
44             printf("B\n");
45         else
46         {
47             cal(str);
48             if(a==ans)
49                 printf("B\n");
50             else
51                 printf("A\n");
52         }
53     }
54 }
posted @ 2012-09-29 19:56  YORU  阅读(283)  评论(0编辑  收藏  举报