拙木鸟


私信TA

用户名:723

访问量:16591

签 名:

等  级
排  名 1192
经  验 2983
参赛次数 0
文章发表 15
年  龄 0
在职情况 学生
学  校 上海大学
专  业

  自我简介:

#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 人评分

  评论区

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