目录
01 判断数正负
02 输出绝对值
03 奇偶数判断
04 奇偶ASCII值判断
05 整数大小比较
06 判断是否为两位数
07 收集瓶盖赢大奖
08 判断一个数能否同时被3和5整除
09 判断能否被3、5、7整除
10 有一门课不及格的学生
11 晶晶赴约会
12 骑车与走路
13 分段函数
14 计算邮资
15 最大数输出
16 三角形判断
17 判断闰年
18 点和正方形的关系
19 简单计算器
01
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if (n>0) cout<<"positive";
else if (n==0) cout<<"zero";
else cout<<"negative";
return 0;
}
本题目主要考察if-else语句的使用
02
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
float a;
cin>>a;
a=abs(a);
cout<<fixed<<setprecision(2)<<a;
return 0;
}
03
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if (n%2==1) cout<<"odd";
else cout<<"even";
return 0;
}
04
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
char c;
scanf("%c",&c);
if ((int)c%2==1) cout<<"YES";
else cout<<"NO";
return 0;
}
这题主要是int-char之间的转换
05
#include <iostream>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
if (a>b) cout<<">";
else if (a==b) cout<<"=";
else cout<<"<";
return 0;
}
06
#include <iostream>
using namespace std;
int main() {
int a;
cin>>a;
if (a>=10&&a<=99) cout<<1;
else cout<<0;
return 0;
}
07
#include <iostream>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
if (a>=10||b>=20) cout<<1;
else cout<<0;
return 0;
}
08
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if (n%3==0&&n%5==0) cout<<"YES";
else cout<<"NO";
return 0;
}
09
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if (n%3==0&&n%5==0&&n%7==0) cout<<"3 5 7";
else if (n%3==0&&n%5==0&&n%7!=0) cout<<"3 5";
else if (n%3==0&&n%5!=0&&n%7==0) cout<<"3 7";
else if (n%3!=0&&n%5==0&&n%7==0) cout<<"5 7";
else if (n%3==0) cout<<"3";
else if (n%5==0) cout<<"5";
else if (n%7==0) cout<<"7";
else cout<<'n';
return 0;
}
10
#include <iostream>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
if (a<60&&b>=60||b<60&&a>=60) cout<<1;
else cout<<0;
return 0;
}
11
#include <iostream>
using namespace std;
int main() {
int a;
cin>>a;
switch (a) {
case 1: case 3: case 5:
cout<<"NO";
break;
default:
cout<<"YES";
break;
}
return 0;
}
12
#include <iostream>
using namespace std;
int main() {
double distance;
int bicycle,walk;
cin>>distance;
bicycle=27+distance/3.0+23;
walk=distance/1.2;
if (walk<bicycle) cout<<"Walk";
else if (walk>bicycle) cout<<"Bike";
else cout<<"All";
return 0;
}
13
#include <iostream>
#include <iomanip>
using namespace std;
double f(double x) {
double y;
if (0<=x&&x<5) {
y=-x+2.5;
} else if (5<=x&&x<10) {
y=2-1.5*(x-3)*(x-3);
} else if (10<=x&&x<20) {
y=x/2.0-1.5;
}
return y;
}
int main() {
double n;
cin>>n;
cout<<fixed<<setprecision(3)<<f(n);
return 0;
}
14
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n,money=0;
char c;
cin>>n>>c;
n-=1000;
money=8;
if (n>0) {
int a=n/500;
n%=500;
if (n>0) {
a++;
}
money+=a*4;
}
if (c=='y') money+=5;
cout<<money;
return 0;
}
15
#include <iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if (a>b&&a>c) cout<<a;
else if (b>a&&b>c) cout<<b;
else if (c>a&&c>b) cout<<c;
return 0;
}
16
#include <iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if (a+b>c&&a+c>b&&b+c>a) {
cout<<"yes";
} else {
cout<<"no";
}
return 0;
}
17
#include <iostream>
using namespace std;
int main() {
int year;
cin>>year;
if (year%100!=0&&year%4==0||year%100==0&&year%400==0) {
cout<<'Y';
} else {
cout<<'N';
}
return 0;
}
18
#include <iostream>
using namespace std;
int main() {
int x,y;
cin>>x>>y;
if (x>=-1&&x<=1&&y>=-1&&y<=1) cout<<"yes";
else cout<<"no";
return 0;
}
19
#include <iostream>
using namespace std;
int main() {
int a,b;
char s;
cin>>a>>b>>s;
switch (s) {
case '+':
cout<<a+b;
break;
case '-':
cout<<a-b;
break;
case '*':
cout<<a*b;
break;
case '/':
if (b==0) {
cout<<"Divided by zero!";
break;
}
cout<<a/b;
break;
default:
cout<<"Invalid operator!";
break;
}
return 0;
}
喜欢的话就点赞关注吧~