#include <stdio.h>
#include<stdlib.h>
int main()
{
    int a, b, c;
    int result;
    char c1, c2, c3[3];    //等式右边用字符串存储,因为可以是三位数
    int k = 0;
    while (scanf("%d%c%d%c%s", &a, &c1, &b, &c2, &c3) == 5) 
    {
        getchar() != EOF;    //这个在输入的时候在新的一行按ctrl+z,或f6回车。如果不行,试试ctrl+d。
        if(c3 != '?')
            c = atoi(&c3);    //转化成整型
        if (c1 == '+')
            result = a + b;
        else
            result = a - b;
        if (result == c)
            k++;
    }
    printf("%d", k);
    system("pause");
    return 0;
}



atoi()函数相关:

http://www.cnblogs.com/bluestorm/p/3168719.html




 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

挺强的写法,比我这个直接scanf("%s",)的好
2017-12-10 13:47:59
if(result==c)   错了吧
2017-07-29 12:19:39
  • «
  • 1
  • »