#include<bits/stdc++.h>
using namespace std;int n, cnt;double x, sum;intmain(){
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);return0;}
括号匹配
#include<bits/stdc++.h>
using namespace std;intmain(){
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 ++;}elseif(s[i]==')'){
cnt --;if(cnt <0){
cout <<"No";return0;}}}if(cnt ==0) cout <<"Yes";else cout <<"No";return0;}
和素数
#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;}intmain(){
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';return0;}
Web浏览
#include<cstdio>#include<iostream>
using namespace std;//题目没有说明数据范围,这里假设1000 constint N =1010;
string url[N];//top指向最后一个url,i指向当前访问的url int top, i;intmain(){
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;}}}return0;}