您的位置:首页 > 其它

NYOJ 663 弟弟的作业【简单题更能体现水平。。。】

2016-08-19 20:28 267 查看

弟弟的作业

时间限制:1000 ms  |  内存限制:65535 KB
难度:1

描述
你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中a和b是作业中给出的,均为不超过100的非负整数;c是弟弟算出的答案,可能是不超过200的非负整数,也可能是单个字符"?",表示他不会算。

输入输入文件包含不超过100行,以文件结束符结尾。每行包含一道题目,格式保证符合上述规定,且不包含任何空白字符。输入的所有整数均不含前导0。输出输出仅一行,包含一个非负整数,即弟弟答对的题目数量。样例输入
1+2=3


3-1=5


6+7=?


99-0=99

样例输出
2

来源湖南省第六届大学生计算机程序设计竞赛

原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=663

简单题,从代码就可以看出水平。

我的丑陋AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
int a,b;
char c[5],op,e;
int cnt=0;
while(cin>>a>>op>>b>>e>>c)
{
cout<<a<<op<<b<<e<<c<<endl;
int ans;
if(c[0]!='?')
ans=atoi(c);
else
continue;
if(op=='+')
{
if(a+b==ans)
cnt++;
}
else if(op=='-')
{
if(a-b==ans)
cnt++;
}
}
cout<<cnt<<endl;
return 0;
}

网上标程代码:

#include<stdio.h>
int main()
{
char s[99];
int a, b, c, n = 0;
while(scanf("%s", &s) == 1)
{
if(sscanf(s, "%d+%d=%d", &a, &b, &c) == 3 && a+b==c) n++;
if(sscanf(s, "%d-%d=%d", &a, &b, &c) == 3 && a-b==c) n++;
}
printf("%d\n", n);
return 0;
}

OJ标程代码:

#include<stdio.h>
int main()
{
int a,b,c,sum=0;
char k;
while(1)
{
switch(scanf("%d%c%d=%d",&a,&k,&b,&c))
{
case 4:
if(k==43&&a+b==c||k==45&&a-b==c)
sum++;
continue;
case 3:
getchar();
continue;
case EOF:
printf("%d\n",sum);
return 0;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息