藜麦小笼包


私信TA

用户名:dotcpp0680909

访问量:609

签 名:

刁常潇

等  级
排  名 400
经  验 5065
参赛次数 0
文章发表 66
年  龄 18
在职情况 学生
学  校 山东管理学院
专  业 软件工程

  自我简介:

一名喜欢走捷径的程序猿

TA的其他文章

参考代码:

#include<bits/stdc++.h>//100以内数的加减
using namespace std;
bool jiancha(string s)
{
    string a,b,c;
    int flag=0;
    if(s[(int)s.size()-1]=='?')
    return false;
    else
    {
        for(int i=0;i<(int)s.size();i++)
        {
            if(s[i]>='0'&&s[i]<='9'&&flag==0)
            {
                a+=s[i];
            }
            if(s[i]>='0'&&s[i]<='9'&&flag==1)
            {
                b+=s[i];
            }
            if(s[i]>='0'&&s[i]<='9'&&flag==2)
            {
                c+=s[i];
            }
            else if(s[i]=='+'||s[i]=='-'||s[i]=='=')
            {
                flag++;
            }
        }
        int a1=stoi(a);
        int b1=stoi(b);
        int c1=stoi(c);
        if((int)s.find('+')!=-1)
        {
            if(a1+b1==c1)
            return true;
            else
            return false;
        }
        else if((int)s.find('-')!=-1)
        {
            if(a1-b1==c1)
            return true;
            else
            return false;
        }
    }
}
int main()
{
    int cnt=0;
    string s;
    while(cin>>s)
    {
        if(jiancha(s)==true)
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


 

0.0分

1 人评分

  评论区

  • «
  • »