#include "stdio.h"
#include "string.h"
int stoi(int n, char s[])
{
int a = 0,t=1;
while (n--)
{
a += t*(s[n]-'0');
t *= 10;
}
return a;
}
int fun(int n, char s[])
{
char num[4][4] = { 0 };
int i, j=0,flag=0;
for (i = 0; i < n; i++)
{
if ((s[i] != '+') && (s[i] != '-')&& flag == 0)
{
num[0][j++] = s[i];
}
else if(flag == 0)
{
num[1][0] = s[i];
j = 0;
flag = 1;
continue;
}
if ((s[i] != '=')&& flag == 1)
{
num[2][j++] = s[i];
}
else if (flag == 1)
{
j = 0;
flag = 2;
continue;
}
if (((s[i] == '?') || (s[i] >= '0') && (s[i] <= '9')) && flag == 2)
{
if (s[i] == '?')
return 0;
else
num[3][j++] = s[i];
}
}
if (num[1][0] == '+')
{
if (stoi(strlen(num[0]), num[0])+ stoi(strlen(num[2]), num[2])== stoi(strlen(num[3]), num[3]))
return 1;
else
return 0;
}
else
{
if (stoi(strlen(num[0]), num[0]) - stoi(strlen(num[2]), num[2]) == stoi(strlen(num[3]), num[3]))
return 1;
else
return 0;
}
}
int main()
{
char s[10] = { 0 };
int c = 0, len;
while (scanf("%s", s) != EOF)
{
len = strlen(s);
if (fun(len, s) == 1)
c++;
memset(s, 0, sizeof(s));
}
printf("%d", c);
return 0;
}
0.0分
0 人评分
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:744 |
C语言程序设计教程(第三版)课后习题6.9 (C++代码)浏览:560 |
2005年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:870 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:602 |
输出九九乘法表 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:747 |
C语言训练-字符串正反连接 (C语言代码)浏览:664 |
C语言训练-排序问题<1> (C++代码)浏览:632 |
打水问题 (C语言代码)浏览:1149 |
【偶数求和】 (C语言代码)浏览:588 |