第二十四届全国青少年信息学奥林匹克联赛入门组复赛

跑动距离

#include <bits/stdc++.h>
using namespace std;

int n, cnt;
double x, sum;

int main() {
    
    
 	freopen("pdjl.in", "r", stdin);
 	freopen("pdjl.out", "w", stdout);
	
	cin >> n;
	for (int i = 1; i <= n; i ++) {
    
    
		cin >> x;
		if (x >= 7000) cnt ++;
		sum += x;		
	}

	printf("%.1f\n", sum / n);
	printf("%d\n", cnt);

	return 0;
}

括号匹配

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    
	freopen("khpp.in", "r", stdin);
	freopen("khpp.out", "w", stdout);

	string s;
	cin >> s;
	
	int cnt = 0;
	for (int i = 0; i < s.size(); i ++) {
    
    
		if (s[i] == '(') {
    
    
			cnt ++;	
		}
		else if (s[i] == ')') {
    
    
			cnt --;
			if (cnt < 0 ) {
    
    
				cout << "No";
				return 0;
			}
		}
	}
	
	if (cnt == 0) cout << "Yes";
	else cout << "No";

	return 0;
}

和素数

#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x) {
    
    
	if (x < 2) return false;
	
	for (int i = 2; i <= x/i; i++) {
    
    
		if (x%i == 0) return false;
	}
	
	return true;
}

int main() {
    
    
	freopen("hss.in", "r", stdin);
	freopen("hss.out", "w", stdout);
	
	int n, k;
	cin >> n >> k;	
	
	int maxx = 0, minn = 2e5, x;
	for (int i = 1; i <= n; i ++) {
    
    
		cin >> x;
		if (x < k) maxx = max(maxx, x);
		if (x > k) minn = min(minn, x);
	}
	
	cout << maxx + minn << endl;
	if (isPrime(maxx + minn)) cout << 'Y';
	else cout << 'F';

	return 0;
}

Web浏览

#include <cstdio>
#include <iostream>
using namespace std;

//题目没有说明数据范围,这里假设1000 
const int N = 1010;
string url[N];
//top指向最后一个url,i指向当前访问的url 
int top, i;

int main() {
    
    
	freopen("web.in", "r", stdin);
	freopen("web.out", "w", stdout);
	
	url[1] = "http://www.sina.com.cn/";
	top = i = 1;
	
	string str;
	while (true) {
    
    
		cin >> str;
		if (str == "QUIT") break;
		
		if (str == "VISIT") {
    
    
			cin >> url[++i];
			top = i;
			cout << url[i] << endl;
		}
		
		if (str == "BACK") {
    
    
			if (i > 1) {
    
    
				i --;
				cout << url[i] << endl;
			}
			else {
    
    
				cout << "ignored" <<endl;
			}
		}
		
		if (str == "FORWARD") {
    
    
			if (i < top) {
    
    
				i ++;
				cout << url[i] << endl;
			}
			else {
    
    
				cout << "ignored" << endl;
			}
		}
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/davidliule/article/details/110520866