• 团体程序设计天梯赛 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
    ", 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!
    ";
    	else if(x == mm[i]) cout << "wan mei!
    ";
    	else cout << "shao chi rou!
    ";
    }
    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 << '
    ' << "AI: ";
    		op1(s);
    		op2(s);
    		op3(s);
    		cout << s << '
    ';
    	}
    	return 0;
    }
    
  • 相关阅读:
    linux/unix下 pid文件作用浅析
    gunicorn启动django时静态文件的加载
    分享30道Redis面试题,面试官能问到的我都找到了
    python利用mongodb上传图片数据 : GridFS 与 bson两种方式
    GridFS大文件的添加、获取、查看、删除
    你真的懂redis吗?
    mongoDB的复制集5----复制集安全(认证,用户,权限)
    MongoDB复制集安全认证
    MongoDB 用户名密码登录
    MongoDB 分片
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308671.html
Copyright © 2020-2023  润新知