69 条题解
-
15
#include <iostream> using namespace std; int a , b , c ; int main(){ cin >> a >> b >> c ; cout << (a+b>c?"yes":"no");//三目运算符最适合这种题了 return 0 ; }
优 化
#include <cstdio> //不需要using namespace std inline int reader(){ //自定义输入函数 int it = 0 , chr = getchar(); //getchar()获取一个字符,以这个为原理自己写个输入 while('0' > chr || chr > '9') chr = getchar(); while('0' <= chr && chr <= '9') it = (it << 1) + (it << 3) + chr - '0' ,chr = getchar() ; return it ; } int main(){ printf("%s",(reader() + reader() > reader() ?"yes":"no")); //快 整 整 1 m s //直接用返回值操作就不用定义变量 //printf() 和 cout 差不多 , 用哪个随便 return 0 ; }
-
4
基本运算符与条件判断的综合运用
对于这种简单题目,题目和代码高度匹配,我们可以总结、分析题目,将之转换成语句。具体操作如下。
读入三个整数a、b、c( 0 < a,b,c < 10000 ),
读入就是cin>>,三个整数意味着我们需要定义三个变量。后面的是数据范围,这代表a、b、c在1到9999的范围为内取值。如果它大于int的取值范围,我们就不能用int了。数据之间用空格隔开,
,这个很重要,在以后很可能成为一个题目的坑,还记得吗,cin>>会输入一个数直到空格。如果前两个数a、b的和大于第三个数c,那么就输出“yes”,
“如果”自然就是if判断的意思,a、b的和大于第三个数c
,就是if语句的条件,转换成代码就是a+b>c
,这里注意,由于+优先级算比>高,所以程序会优先执行+运算,不用加括号。那么就输出“yes”,
,就是”输出“就是cout<<,”输出yes“就是cout<<"yes";注意,由于是输出字符串,要加”“;- `否则就输出“no”,就是else。输出“no”转代码也就是cout<<"no";
综合上述,可得AC代码如下(求赞):
/*题目: 读入三个整数a、b、c( 0 < a,b,c < 10000 ), 数据之间用空格隔开, 如果前两个数a、b的和大于第三个数c,那么就输出“yes”, 否则就输出“no”。 */ #include <bits/stdc++.h> using namespace std; int main() { int a,b,c;//定义,由于数据范围较小,用int。 cin>>a>>b>>c;//输入,前提是三数间有空格(第1、2步); if (a+b>c)//如果前两个数a、b的和大于第三个数c。(第3步) { cout<<"yes";//输出“yes”(第3步)。 } else//否则 { cout<<"no";//就输出“no”。(第4步)。 } return 0; }
-
0
这道题也是SO EASY!用了最简单的
if
分支判断来解决,下面“Daima time"(中二病发癫晚期,不必理睬,dog)#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c;//输入a,b,c三个整数 cin>>a>>b>>c;//定义这三个数 if(a+b>c){ cout<<"yes";//判断是否符合条件,符合输出yes }else{ cout<<"no"; }//如果不符合输出no return 0; }
现在便到了喜闻乐见的习惯养成环节。 一定
不要加上return 0
! (静说瞎话ing)点个赞吧❤️
信息
- ID
- 30
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 4
- 标签
- 递交数
- 12403
- 已通过
- 5727
- 上传者