解题思路:想办法把输入的字符串转化为数字再进行判断即可
注意事项:
参考代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
bool yn(char a[]) {
int i = 0, x, y, z, fu;
char b[10], c[10], d[10];
int len = strlen(a);
for (int j = 0; j < len; j++) {
if (a[j] == '?')
return false;
}
while (a[i] != '+' && a[i] != '-') {
b[i] = a[i];
i++;
}
fu = i;
x = atoi(b);
i++;
int k = 0;
while (a[i] != '=') {
c[k] = a[i];
k++;
i++;
}
y = atoi(c);
i++;
int p = 0;
while (a[i] != '\0') {
d[p] = a[i];
p++;
i++;
}
z = atoi(d);
if (a[fu] == '+') {
if (x + y == z)
return true;
else
return false;
}
if (a[fu] == '-') {
if (x - y == z)
return true;
else
return false;
}
}
int main() {
char a[50];
int sum = 0;
while (gets(a)) { //若换成while(scanf("%s",a)!=EOF)则会被判WA,想想为什么
if (yn(a))
sum++;
}
cout << sum;
return 0;
}
0.0分
2 人评分
A+B for Input-Output Practice (C++代码)浏览:609 |
拆分位数 (C语言代码)浏览:1328 |
Pascal三角 (C语言代码)浏览:1188 |
C语言考试练习题_排列 (C语言代码)浏览:725 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:661 |
WU-整除问题 (C++代码)浏览:612 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:832 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:588 |
字符删除 (C语言代码)浏览:721 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1189 |