L1-062 幸运彩票(C++)

原题链接:L1-062 幸运彩票 - 团体程序设计天梯赛-练习集

彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:

输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:

对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:

2
233008
123456

输出样例:

You are lucky!
Wish you good luck.

以下是我的题解:

#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	while (N--) {
		string number;
		cin >> number;
		int sum1 = 0, sum2 = 0;
		for (int i = 0; i < 3; i++) {
			sum1 += number[i] - '0';//-'0的操作相当于将字符数字转换为对应的整数值
		}
		for (int i = 3; i < 6; i++) {
			sum2 += number[i] - '0';
		}
		if (sum1 == sum2) {
			cout << "You are lucky!" << endl;
		}
		else {
			cout << "Wish you good luck." << endl;
		}
	}
	return 0;
}

简单,秒了

### L1-069 胎压监测 C++ 实现 对于L1-069胎压监测问题,在C++中的实现主要围绕读取输入数据并判断轮胎压力是否正常展开。程序会接收一系列浮点数作为不同轮胎的压力值,并依据设定的标准来决定这些轮胎是否存在异常情况。 当处理这类问题时,可以定义一个函数用于解析输入的数据流,随后通过条件语句评估每一个轮胎的状态: ```cpp #include <iostream> #include <vector> using namespace std; bool checkPressure(float pressure, float threshold) { return abs(pressure - 32.0f) > threshold; // 判断单个轮胎气压是否超出阈值[^1] } int main() { vector<float> pressures; const int numTires = 4; float input; cout << "Enter the tire pressures (in PSI): "; for(int i=0;i<numTires;++i){ cin >> input; pressures.push_back(input); } bool alertNeeded = false; float warningThreshold = 3.0f; // 设定警告阈值 for(auto& p : pressures){ if(checkPressure(p,warningThreshold)){ alertNeeded=true; break; } } if(alertNeeded){ cout<<"Warning! One or more tires have abnormal pressure."<<endl; }else{ cout<<"All tires are within normal operating range."<<endl; } return 0; } ``` 上述代码展示了如何创建一个简单的命令行应用程序来进行基本的胎压监控操作。这里假设标准工作气压为32PSI,允许的最大偏差范围由`warningThreshold`变量指定。如果任何一个轮胎的实际测量值偏离此标准超过给定限度,则触发警报机制通知驾驶员注意安全驾驶[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值