团体程序设计天梯赛 L1-061~L1-064

L1-061

思路:

计算并判断即可

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {	
	double m, h;
	cin >> m >> h;
	double x = m / (h * h);
	printf("%.1f\n", x);
	if(x > 25) puts("PANG");
	else puts("Hai Xing");
	return 0;
}

L1-062

思路:

计算并判断即可

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {	
	int n;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		int x = 0, y = 0;
		for(int i = 0; i < 3; i++) x += s[i] - '0';
		for(int i = 3; i < 6; i++) y += s[i] - '0';	
		if(x == y) puts("You are lucky!");
		else puts("Wish you good luck.");
	}
	return 0;
}

L1-063

思路:

计算一下,按要求判断输出即可

代码:

#include<bits/stdc++.h>

using namespace std;

int hh[2] = {129, 130};
int mm[2] = {25, 27};

void jdh(int & x, int & i){
	if(x < hh[i]) cout << "duo chi yu! ";
	else if(x == hh[i]) cout << "wan mei! ";
	else cout << "ni li hai! ";
}
void jdm(int & x, int & i){
	if(x < mm[i]) cout << "duo chi rou!\n";
	else if(x == mm[i]) cout << "wan mei!\n";
	else cout << "shao chi rou!\n";
}
int main() {	
	int kase;
	cin >> kase;
	while(kase--){
		int sex, m, h;
		cin >> sex >> h >> m;
		jdh(h, sex);
		jdm(m, sex);	
	}
	return 0;
}

L1-064

思路:

真的真的非常想diss这题,主要就是有歧义吧,“原文中”忽而指修改前的忽而指修改后的;
相邻[单词]间的多余空格删掉,好像大家都是把所有多余空格删去了?
这不严谨吧。。
希望自己比赛别遇到这些题吧。。
剩下的就是模拟(L1模拟成这样真是丧心病狂嗷
(PS:有个大佬用c++的正则表达式做的,大家有兴趣可以试一试)

代码:

#include<bits/stdc++.h>

using namespace std;
#define isp(c) (!isalpha(c) && !isdigit(c))  //不字母且不是数字 
#define len s.length()
void op1(string & s) {
	while(len && s[0] == ' ') { s.erase(0, 1); };
	while(len && s[len - 1] == ' ') { s.erase(len - 1, 1); };
	for(int i = 0; i < len; i++) while(s[i] == ' ' && s[i + 1] == ' ') s.erase(i + 1, 1);
	for(int i = 0; i < len; i++) if(isp(s[i]) && s[i] != ' ' && i && s[i - 1] == ' ') { s.erase(i - 1, 1); i -= 2; }
}
void op2(string & s) { for(char & c : s) if(c != 'I') c = tolower(c); }
#define isd(i, j) ((i == 0 ||isp(s[i - 1])) && (j + 1 == len || isp(s[j + 1]))) //  s[i...j]是独立的 
void op3(string & s) {
	for(int i = 0; i < len; i++) {
		if(s[i] == 'I' && isd(i, i)) { s.replace(i, 1, "you"); i += 2; continue; }
		if(i + 1 < len && s.substr(i, 2) == "me" && isd(i, i + 1)) { s.replace(i, 2, "you"); i += 2; continue; }
		if(s[i] == '?') { s[i] = '!'; continue; }
		if(i + 6 < len && s.substr(i, 7) == "can you" && isd(i, i + 6))
		{ s.replace(i, 7, "I can"); i += 4; continue; }
		if(i + 8 < len && s.substr(i, 9) == "could you" && isd(i, i + 8))
		{ s.replace(i, 9, "I could"); i += 6; continue; }
	}
}

int main() {
#ifdef MyTest
	freopen("Sakura.txt", "r", stdin);
#endif	
	int kase;
	cin >> kase;
	getchar();
	while(kase--) {
		string s;
		getline(cin, s);
		cout << s << '\n' << "AI: ";
		op1(s);
		op2(s);
		op3(s);
		cout << s << '\n';
	}
	return 0;
}
发布了280 篇原创文章 · 获赞 7 · 访问量 6699

猜你喜欢

转载自blog.csdn.net/qq_45228537/article/details/104032096