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


弟弟的作业

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

你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中ab是作业中给出的,均为不超过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;
		}
	}
}        


  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值