Advertisement

上海市计算机学会月赛2020年4月丙组

阅读量:
竞选班长
复制代码
    #include <iostream>
    using namespace std;
    
    int main() {
    	int x, cnt = 0;
    	for (int i = 1; i <= 3; i ++) {
    		cin >> x;
    		if (x >= 90) cnt ++;
    	}
    	cin >> x;
    	
    	if (cnt >= 2 && x >= 85) puts("Qualified");
    	else puts("Not qualified");
    
    	return 0;
    }
生命游戏
复制代码
    #include <iostream>
    using namespace std;
    
    int n, m;
    char a[105][105];
    
    int main() {
    	cin >> n >> m;	
    	for (int i = 1; i <= n; i ++ ) {
    		for (int j = 1; j <= m; j ++ ) {
    			cin >> a[i][j];
    		}
    	}
    
    	for (int i = 1; i <= n; i ++ ) {
    		for (int j = 1; j <= m; j ++ ) {
    			int cnt = 0;
    			
    			for (int x = i - 1; x <= i + 1; x ++ ) {
    				for (int y = j - 1; y <= j + 1; y ++ ) {
    					if (a[x][y] == '*') cnt ++ ;
    				}
    			}
    			
    			if (a[i][j] == '*') {
    				if (cnt < 3 || cnt > 4) {
    					puts("Other");
    					return 0;
    				}
    			}
    			else {
    				if (cnt == 3) {
    					puts("Other");
    					return 0;
    				}
    			}			
    
    		}
    	}
    	
    	puts("Still life");
    	
    	return 0;
    }
直线运输
复制代码
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    int main() {
    	int n, x;
    	long long sum = 0, res = 0;
    	cin >> n; 
    	
    	for (int i = 0; i < n; i ++ ) {
    		cin >> x;
    		sum += x;
    		res += abs(sum);
    	}
    	
    	cout << res;
    				
    	return 0;
    }
数字验证
复制代码
    #include <iostream>
    using namespace std;
    
    int main() {
    	string s;
    	cin >> s;
    	
    	if (s[0] == '+' || s[0] == '-') s = s.substr(1);
    	
    	if (s == ".") {
    		puts("Invalid");
    		return 0;
    	}
    	
    	int cnt = 0;
    	for (int i = 0; i < s.size(); i ++ ) {
    		if (s[i] == '.') {
    			cnt ++ ;
    			if (cnt > 1) {
    				puts("Invalid");
    				return 0;				
    			}
    		}
    		else if (s[i] < '0' || s[i] > '9') {
    			puts("Invalid");
    			return 0;			
    		}
    	}
    	
    	puts("Valid");
    
    	return 0;
    }
导购员
复制代码
    #include <iostream>
    using namespace std;
    
    const int N = 1e6 + 5;
    int n, cnt = 0, a[N], b[N];
    
    int main() {
    cin >> n;
    
    for (int i = 0; i < n; i ++ ) {
        cin >> a[i];
        b[a[i]] ++ ;
    }
    
    for (int i = 0 ; i < N; i ++ ) {
        if (cnt + b[i] <= i) cnt += b[i];
        else cnt = i + 1;
    }
    
    cout << cnt;
    
    return 0;
    }

全部评论 (0)

还没有任何评论哟~