Group Programming ladder match L1-031 ~ L1-035

L1-031

Ideas:

Press to determine the meaning of the questions

Code:

#include<bits/stdc++.h>

using namespace std;

int main() {	
	int n;
	cin >> n;
	while(n--){
		double h, w;
		cin >> h >> w;
		double ww = (h - 100) * 1.8;
		if(abs(ww - w) < ww * 0.1) puts("You are wan mei!");
		else if(ww - w >= ww * 0.1) puts("You are tai shou le!");
		else puts("You are tai pang le!");
	}
	return 0;
}

L1-032

Thinking:

If the length exceeds the subtracted preceding string

of code:

#include<bits/stdc++.h>

using namespace std;

int main() {	
	int n;
	char c;
	string s;
	cin >> n >> c;
	getchar();
	getline(cin, s);
	reverse(s.begin(), s.end());
	if(n <= s.length()) s = s.substr(0, n);
	int k = n - s.length();
	while(k--) putchar(c);
	reverse(s.begin(), s.end());
	cout << s;
	return 0;
}

L1-033

Thinking:

write function calculation is repeated up to the number of digits, and then successively to traverse

the code:

#include<bits/stdc++.h>

using namespace std;

int cal(int x) {
	unordered_map<int, bool> mp;
	int ans = 0;
	if(x < 1000) mp[0] = true, ++ans;
	while(x) {
		if(mp[x % 10] == false) ++ans, mp[x % 10] = true;
		x /= 10;
	}
	return ans;
}

int main() {	
	int y, n;
	cin >> y >> n;
	for(int i = 0; ; i++){
		if(cal(y + i) == n){
			printf("%d %04d", i, y + i);
			break;	
		}
	}
	return 0;
}

L1-034

Ideas:

with pair number and the number of storage, you can then customize the collation

of code:

#include<bits/stdc++.h>

using namespace std;
typedef pair<int, int> P;
#define fi first
#define sc second
const int maxn = 1005;
P arr[maxn];

bool cmp(P & a, P & b){
	return a.sc == b.sc ? a.fi > b.fi : a.sc > b.sc;
}

int main() {	
	int n, k, f;
	cin >> n;
	for(int i = 0; i < maxn; i++){
		arr[i].fi = i;
		arr[i].sc = 0;	
	}
	for(int i = 0; i < n; i++){
		cin >> k;
		while(k--){
			cin >> f;
			++arr[f].sc;
		}
	}
	sort(arr, arr + maxn, cmp);
	cout << arr[0].fi << ' ' << arr[0].sc;
	return 0;
}

L1-035

Ideas:

Statistical input comes to the number of strings

of code:

#include<bits/stdc++.h>

using namespace std;

int main() {	
	int ans = 0;
	string a, b, s;
	while(cin >> s){
		if(s == ".") break;
		++ans;
		if(ans == 2) a = s;
		else if(ans == 14) b = s;
	}
	if(ans < 2) cout << "Momo... No one is for you ...";
	else if(ans < 14) cout << a + " is the only one for you...";
	else cout << a + " and " + b + " are inviting you to dinner...";
	return 0;
}
Published 281 original articles · won praise 7 · views 6709

Guess you like

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