晨三娃


私信TA

用户名:13008142306

访问量:20967

签 名:

我的语言,没有对象

等  级
排  名 381
经  验 4956
参赛次数 6
文章发表 28
年  龄 20
在职情况 学生
学  校 西华大学
专  业 计算机科学与技术

  自我简介:

解题思路:

重点在字符串转数字方面




注意事项:





参考代码:

#include <iostream>

#include <string>

using namespace std;

int main ()

{

int n=0;

string str;

while(cin>>str)

{

int len=str.size(),i;

string str1,str2;

bool f1=true,f2=true;

for(i=0;i<len;i++)

{

if(str.at(i)=='+') {

f1=false;

continue;

}

else if(str.at(i)=='-') {

f1=false;

f2=false;

continue;

}

if(str.at(i)=='=') break;

if(f1) str1.push_back(str.at(i));

else str2.push_back(str.at(i));

}

if(str.at(i+1)=='?') continue;

int a=0,b=0,c=0;

for(int j=0;j<str1.size();j++)

a=a*10+(str1.at(j)-'0');

for(int j=0;j<str2.size();j++)

b=b*10+(str2.at(j)-'0');

for(int j=1;j+i<str.size();j++)

c=c*10+(str.at(j+i)-'0');

if(f2 && c==a+b) n++;

else if(!f2 && c==a-b) n++;

}

cout<<n<<endl;

return 0;


 

0.0分

0 人评分

  评论区