#include<bits/stdc++.h>
using namespace std;
int main()
{
char str[15],ch;
int i,j,k,len,x,y,a,b,c,tag,counter=0,temp;
while(gets(str))
{
if(str[0]=='\0')
{
break;
}
len=strlen(str);
y=0;
for(i=0;i<len;i++)
{
if(str[i]!='+' && str[i]!='-')
{
x=y*10+str[i]-48;
y=x;
}
else if(str[i]=='+')
{
a=x;
ch=str[i];
y=0;
break;
}
else if(str[i]=='-')
{
a=x;
ch=str[i];
y=0;
break;
}
}
for(j=i+1;j<len;j++)
{
if(str[j]!='=')
{
x=y*10+str[j]-48;
y=x;
}
else if(str[j]=='=')
{
b=x;
y=0;
break;
}
}
tag=0;
for(k=j+1;k<=len;k++)
{
if(str[k]=='?')
{
tag=1;
break;
}
else if(str[k]!='\0')
{
x=y*10+str[k]-48;
y=x;
}
else if(str[k]=='\0')
{
c=x;
break;
}
}
if(tag==1)
{
continue;
}
else
{
if(ch=='+')
{
temp=a+b;
if(temp==c)
{
counter++;
}
}
else if(ch=='-')
{
temp=a-b;
if(temp==c)
{
counter++;
}
}
}
}
printf("%d\n",counter);
return 0;
}
using namespace std;
int main()
{
char str[15],ch;
int i,j,k,len,x,y,a,b,c,tag,counter=0,temp;
while(gets(str))
{
if(str[0]=='\0')
{
break;
}
len=strlen(str);
y=0;
for(i=0;i<len;i++)
{
if(str[i]!='+' && str[i]!='-')
{
x=y*10+str[i]-48;
y=x;
}
else if(str[i]=='+')
{
a=x;
ch=str[i];
y=0;
break;
}
else if(str[i]=='-')
{
a=x;
ch=str[i];
y=0;
break;
}
}
for(j=i+1;j<len;j++)
{
if(str[j]!='=')
{
x=y*10+str[j]-48;
y=x;
}
else if(str[j]=='=')
{
b=x;
y=0;
break;
}
}
tag=0;
for(k=j+1;k<=len;k++)
{
if(str[k]=='?')
{
tag=1;
break;
}
else if(str[k]!='\0')
{
x=y*10+str[k]-48;
y=x;
}
else if(str[k]=='\0')
{
c=x;
break;
}
}
if(tag==1)
{
continue;
}
else
{
if(ch=='+')
{
temp=a+b;
if(temp==c)
{
counter++;
}
}
else if(ch=='-')
{
temp=a-b;
if(temp==c)
{
counter++;
}
}
}
}
printf("%d\n",counter);
return 0;
}
0 comments: (+add yours?)
Post a Comment