Group Programming ladder match L1-061 ~ L1-064

L1-061

Thinking:

Calculation and determination to

the code:

#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

Thinking:

Calculation and determination to

the code:

#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

Thinking:

calculation, determines the required output to

the code:

#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

Thinking:

really, really want to diss this problem, it is mainly ambiguous, "the original" refers to the suddenly suddenly before the amendment refers to modifications;
adjacent [ word extra spaces between] deleted, as if we are all to All the extra space by deleting?
This is not rigorous bar. .
I hope I do not encounter these problems right game. .
The rest is analog ( L1 simulation like this is really insane wailing
(PS: There is a big brother with c ++ regular expression to do, we are interested can try)

Code:

#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;
}
Published 280 original articles · won praise 7 · views 6699

Guess you like

Origin blog.csdn.net/qq_45228537/article/details/104032096