Sapphire
2022/2/23
解题思路:
建议直接看题解。
你可能有的疑惑:
1.为什么要 char d[3] 而不直接 char d?
答:因为当你输入99到d时,如果是char d,只能读取到9这个字符,所以我们只好放弃用d-'0'这样的思路。
2.atoi函数的作用是?
答:atoi函数藏在头文件stdlib.h里,作用是将字符串转换成整型数字。
参考代码:
#include<stdio.h> #include<stdlib.h> int main() { int a,b; char c; char d[3]; int k; int count=0; while(~(k=scanf("%d%c%d=%s",&a,&c,&b,d))) { if((a>=0&&a<=100)&&(b>=0&&b<=100)) { if((c=='+')&&(a+b==atoi(d)))count++; if((c=='-')&&(a-b==atoi(d)))count++; } } printf("%d",count); return 0; }
该代码的优越性在于,不用考虑当d为'?'时的这一特殊情况,只要满足两个if,count++。
0.0分
2 人评分
WU-蓝桥杯算法提高VIP-Quadratic Equation (C++代码)浏览:1807 |
1126题解浏览:647 |
剪刀石头布 (C++代码)浏览:1808 |
理财计划 (C语言代码)浏览:493 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:494 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:534 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:543 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:645 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:487 |
10月月赛题解浏览:552 |