zoukankan      html  css  js  c++  java
  • 团体程序设计天梯赛 L1-031~L1-035

    L1-031

    思路:

    按题意判断即可

    代码:

    #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

    思路:

    如果长度超过了需要减去前面的字符串

    代码:

    #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

    思路:

    写个计算最多不重复数字个数的函数,然后依次遍历即可

    代码:

    #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

    思路:

    用pair存储编号和次数,然后自定义排序规则即可

    代码:

    #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

    思路:

    统计输入进来的字符串个数即可

    代码:

    #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;
    }
    
  • 相关阅读:
    Java硬件同步机制Swap指令模拟+记录型信号量模拟
    算法(第四版)练习 1.1.26 ~ 1.1.31
    C++ 电路布线/最短路径问题
    线性代数笔记
    算法导论(第三版)练习 2.2-1 ~ 2.2-4
    条款45: 弄清C++在幕后为你所写、所调用的函数
    条款42: 明智地使用私有继承
    条款41: 区分继承和模板
    【python】字符遍历
    【python】range的用法
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308679.html
Copyright © 2011-2022 走看看