Chocolaid


私信TA

用户名:318013612

访问量:1638

签 名:

等  级
排  名 5554
经  验 1470
参赛次数 0
文章发表 9
年  龄 0
在职情况 学生
学  校 哈尔滨工业大学(威海)
专  业

  自我简介:

TA的其他文章

解题思路:想办法把输入的字符串转化为数字再进行判断即可

注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区