1. 谁洗碗
【问题描述】谁洗碗。小明比较疼爱妹妹,天天和妹妹抽纸牌(1~13张)决定谁洗碗。妹妹洗碗的条件是:纸牌抽三次,最小牌面点数是1才洗碗。请问,今天小明妹妹洗碗了吗?程序运行时让小明妹妹输入一个幸运数(作为种子),决定她是否洗碗。
纸牌模拟:srand和rand函数。
【输入形式】输入一个整数作为幸运数。
【输出形式】洗碗输出YES,否则输出NO。输出单独占一行。
【样例输入】30
【样例输出】NO
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
srand(a);
int b = rand() % 13 + 1;
if (b == 1)
cout << "Yes";
else
cout << "No";
return 0;
}
2. 判断成绩等第
【问题描述】用户输入一个百分制成绩(整型),程序输出成绩等第:90~100为A等,80~89为B等,70~79为C等,60~69为D等,0~59为F等。非百分制成绩输出ERROR。
【输入形式】输入一个百分制成绩
【输出形式】输出对应等第:A、B、C、D或F。单独占一行。
【样例输入】91
【样例输出】A
【样例输入】-78
【样例输出】ERROR
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a >= 0 && a <= 100)
{
if (a >= 90)
cout << 'A';
else if (a >= 80)
cout << 'B';
else if (a >= 70)
cout << 'C';
else if (a >= 60)
cout << 'D';
else if (a >= 0)
cout << 'F';
}
else
cout << "ERROR";
return 0;
}
3. 判断整数的正负
【问题描述】判断整数的正负。让用户输入一个整数,程序判断它是大于0、小于0还是等于0,并给出判定结果:Positive Integer、Negative Integer或 Zero(即输出这些判断结果)。
【输入形式】让用户输入一个整数
【输出形式】输出判定结果:Positive Integer、Negative Integer或 Zero
【样例输入】89
【样例输出】Positive Integer
#include<iostream>
using namespace std;
int main()
{
int i;
cin >> i;
if (i > 0)
cout << "Positive Integer";
else if (i < 0)
cout << "Negative Integer";
else
cout << " Zero";
return 0;
}
4. 商场折扣活动
【问题描述】商场折扣活动。“买买买”商城进行国庆大促销活动。活动规则为:购物满5000元,打55折;5000元以下、3000元以上,打65折;3000元以下、1000元以上,打8折;1000元以下、200元以上打9折;200元以下不打折。编程输入购物金额输出应付金额。
【输入形式】输入购物金额
【输出形式】输出应付金额,购物金额为负输出ERROR。
【样例输入】7896.39
【样例输出】4343.01
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double a;
cin >> a;
if (a > 0)
{
if (a >= 5000)
cout << fixed<<setprecision(2)<<a * 0.55;
else if (a >= 3000)
cout << fixed << setprecision(2) << a * 0.65;
else if (a >= 1000)
cout << fixed << setprecision(2) << a * 0.8;
else if (a >= 200)
cout << fixed << setprecision(2) << a * 0.9;
else
cout << fixed << setprecision(2) << a;
}
else
cout << "ERROR";
return 0;
}