PAT乙级题目答案汇总PAT (Basic Level) Practice (中文)

1001 害死人不偿命的(3n+1)猜想 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	int cnt=0;
	while(n!=1){
		if(n%2==0){
			n/=2;
		} else {
			n=(3*n+1)/2;
		}
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



1002 写出这个数 (20 分)

#include<bits/stdc++.h>
using namespace std;
string sc[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s; cin>>s;
	int cnt=0;
	for(int i=0; i<s.size(); i++){
		cnt+=s[i]-'0';
	}
	s=to_string(cnt);
	for(int i=0; i<s.size(); i++){
		if(i!=0) cout<<" ";
		cout<<sc[s[i]-'0'];
	}
	return 0;
}




1003 我要通过! (20 分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	while(n--){
		string s; cin>>s;
		int nump=0,numt=0,numo=0,p,t;
		for(int i=0; i<s.size(); i++){
			if(s[i]=='P'){
				nump++; p=i;
			} else if(s[i]=='T'){
				numt++; t=i;
			} else if(s[i]!='A'){
				numo++;
			}
		}
		if(nump!=1 || numt!=1 || numo || t-p<2){
			cout<<"NO"<<endl; continue;
		}
		if((t-p-1)*p==(s.size()-t-1)) cout<<"YES"<<endl; else cout<<"NO"<<endl;
	}
	return 0;
}



1004 成绩排名 (20 分)

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct node{
	string name,id; int cj;
}stu[maxn];
bool cmp(node a,node b){
	return a.cj>b.cj;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		string name,id; int cj; cin>>name>>id>>cj;
		stu[i].name=name,stu[i].id=id,stu[i].cj=cj;
	}
	sort(stu+1,stu+1+n,cmp);
	cout<<stu[1].name<<" "<<stu[1].id<<endl;
	cout<<stu[n].name<<" "<<stu[n].id<<endl;
	return 0;
}



1005 继续(3n+1)猜想 (25 分)

#include <bits/stdc++.h>
using namespace std;
int num[110];
bool ok[110];
int main(){
	int k; cin >> k;
	memset(ok,1,sizeof(ok));
	for(int i=1; i<=k; i++) cin >> num[i];
	for(int i=1; i<=k; i++){
		if(ok[num[i]]){
			int t = num[i];
			while(t != 1){
				if(t%2 == 1){
					t = (3*t+1)/2;
					if(t<110) ok[t] = 0;
				} else {
					t = t/2;
					if(t<110) ok[t] = 0;
				}
			}
		}
	}
	vector<int>ans;
	for(int i=1; i<=k; i++){
		if(ok[num[i]]) ans.push_back(num[i]);
	}
	sort(ans.begin(),ans.end());
	for(int i=ans.size()-1; i>=0; i--){
		if(i!=ans.size()-1) cout << " "; cout << ans[i];
	}
	return 0;
}



1006 换个格式输出整数 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s; cin>>s;
	if(s.size()==1){
		int n=s[0]-'0';
		for(int i=1; i<=n; i++) cout<<i;
	} else if(s.size()==3){
		int n=s[0]-'0';
		for(int i=1; i<=n; i++) cout<<"B";
		n=s[1]-'0';
		for(int i=1; i<=n; i++) cout<<"S";
		n=s[2]-'0';
		for(int i=1; i<=n; i++) cout<<i;
	} else {
		int n=s[0]-'0';
		for(int i=1; i<=n; i++) cout<<"S";
		n=s[1]-'0';
		for(int i=1; i<=n; i++) cout<<i;
	}
	return 0;
}


1007 素数对猜想 (20 分)

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
bool is_prime[maxn];
int prime[maxn];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	memset(is_prime,1,sizeof(is_prime));
	is_prime[0]=is_prime[1]=0;
	int cnt=1;
	for(int i=2; i<=n; i++){
		if(is_prime[i]){
			prime[cnt++]=i;
			for(int j=i*2; j<=n; j+=i){
				is_prime[j]=0;
			}
		}
	}
	int ans=0;
	for(int i=2; i<=cnt-1; i++){
		if(prime[i]-prime[i-1]==2) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



1008 数组元素循环右移问题 (20 分)

#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
int a[maxn];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n,m; cin>>n>>m; m%=n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
	} 
	vector<int>ans;
	for(int i=n-m+1; i<=n; i++){
		ans.push_back(a[i]);
	}
	for(int i=1; i<=n-m; i++){
		ans.push_back(a[i]);
	}
	for(int i=0; i<n; i++){
		if(i!=0) cout<<" ";
		cout<<ans[i];
	}
	return 0;
}



1009 说反话 (20 分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	stack<string>st;
	string s;
	while(cin>>s){
		st.push(s);
	}
	while(st.size()){
		cout<<st.top();
		if(st.size()!=1) cout<<" ";
		st.pop();
	} 
	return 0;
}


1010 一元多项式求导 (25 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b; bool ok = 0;
	while(cin >> a >> b){
		if(b != 0){
			if(ok) cout<<" ";
			cout<<a*b<<" "<<b-1;
			ok=1;
		}
	}
	if(!ok) cout<<"0 0"<<endl;
	return 0;
}



1011 A+B 和 C (15 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin>>t;
	for(int i=1; i<=t; i++){
		ll a,b,c; cin>>a>>b>>c;
		if(a+b>c) cout<<"Case #"<<i<<": true"<<endl;
		else cout<<"Case #"<<i<<": false"<<endl;
	}
	return 0;
}



1012 数字分类 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	//ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int a1=0,a2=0,a3=0,a4=0,a5=0;
	int n; cin>>n;
	vector<int>ve; //a2
	int cnt4=0; //a4
	int max5=0; //a5;
	for(int i=1; i<=n; i++){
		int x; cin>>x;
		if(x%5==0){
			if(x%2==0) a1+=x;
		} else if(x%5==1){
			ve.push_back(x);
		} else if(x%5==2){
			a3++;
		} else if(x%5==3){
			a4+=x; cnt4++;
		} else {
			if(x>max5){
				max5=x;
			}
		}
	}
	if(a1!=0) cout<<a1<<" "; else cout<<"N"<<" ";
	int cnt2=0; bool ok=1;
	for(int i=0; i<ve.size(); i++){
		if(ok) cnt2+=ve[i]; else cnt2-=ve[i];
		if(ok==1) ok=0; else ok=1;
	}
	if(ve.size()!=0) cout<<cnt2<<" "; else cout<<"N"<<" ";
	if(a3!=0) cout<<a3<<" "; else cout<<"N"<<" ";
	if(a4!=0){
		printf("%.1lf ",1.0*a4/cnt4);
	} else {
		cout<<"N"<<" ";
	}
	if(max5!=0) cout<<max5<<endl; else cout<<"N"<<endl;
	return 0;
}



1013 数素数 (20 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6;
bool isprime[maxn];
int prime[maxn];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int m,n; cin>>m>>n;
	int cnt=1;
	for(int i=2; i<=maxn; i++){
		if(!isprime[i]){
			prime[cnt++]=i;
			for(int j=i*2; j<=maxn; j+=i){
				isprime[j]=1;
			}
		}
	}
	cnt=0;
	for(int i=m; i<=n; i++){
		cout<<prime[i];
		cnt++;
		if(i==n) break;
		if(cnt==10){
			cout<<endl; cnt=0;
		} else {
			cout<<" ";
		}
	}
	return 0;
}



1014 福尔摩斯的约会 (20 分)

#include <bits/stdc++.h>
using namespace std;
string xq[]={"ww","MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(){
	//ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4;
	int p=min(s1.size(),s2.size());
	int ok=0;
	char xinqi,hh;
	for(int i=0; i<p; i++){
		if(s1[i]==s2[i]){
			if((s1[i]>='A' && s1[i]<='G') && ok==0){
				xinqi=s1[i]; ok=1;
			} else if(((isdigit(s1[i])) || (s1[i]>='A'&&s1[i]<='N')) && ok==1){
				hh=s1[i]; break;
			}
		}
	}
	cout<<xq[xinqi-'A'+1]<<" ";
	if(isdigit(hh)){
		printf("%02d:",hh-'0');
	} else {
		printf("%02d:",hh-'A'+10);
	}
	p=min(s3.size(),s4.size());
	for(int i=0; i<p; i++){
		if(s3[i]==s4[i]&&isalpha(s3[i])){
			printf("%02d",i);
			break;
		}
	}
	return 0;
}



1015 德才论 (25 分)

#include <bits/stdc++.h>
using namespace std;
struct node{
	string id; int de,cai;
};
bool cmp(node a,node b){
	if((a.de+a.cai)!=(b.de+b.cai)) return (a.de+a.cai)>(b.de+b.cai);
	if(a.de!=b.de) return a.de>b.de;
	return a.id<b.id;
}
int main(){
	int n,l,h,cnt=0; cin >> n >> l >> h;
	vector<node>v[5];
//	v[0].push_back(node{"0",0,0});
	for(int i=1; i<=n; i++){
		string id; int de,cai; cin>>id>>de>>cai;
		if(de<l || cai<l) continue;
		cnt++;
		if(de>=h && cai>=h) v[1].push_back(node{id,de,cai});
		else if(de>=h) v[2].push_back(node{id,de,cai});
		else if(de>=cai) v[3].push_back(node{id,de,cai});
		else v[4].push_back(node{id,de,cai});
	}
	for(int i=1; i<=4; i++){
		sort(v[i].begin(),v[i].end(),cmp);
	}
	cout << cnt<<endl;
	for(int i=1; i<=4; i++){
		for(int j=0; j<v[i].size(); j++){
			cout<<v[i][j].id<<" "<<v[i][j].de<<" "<<v[i][j].cai<<endl;
		}
	}
	return 0;
}



1016 部分A+B (15 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string a,b; int da,db; cin>>a>>da>>b>>db;
	int cnta=0,cntb=0;
	for(int i=0; i<a.size(); i++){
		if((a[i]-'0')==da){
			cnta++;
		}
	}
	for(int i=0; i<b.size(); i++){
		if((b[i]-'0')==db) cntb++;
	}
	int pa=0,pb=0;
	for(int i=1; i<=cnta; i++){
		pa=pa*10+da;
	}
	for(int i=1; i<=cntb; i++){
		pb=pb*10+db;
	}
	cout<<pa+pb<<endl;
	return 0;
}



1017 A除以B (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string a; int b; cin>>a>>b;
	int t,tmp;
	t=(a[0]-'0')/b;
	tmp=(a[0]-'0')%b;
	if(t!=0||a.size()==1){
		cout<<t;
	}
	for(int i=1; i<a.size(); i++){
		t=(tmp*10+a[i]-'0')/b;
		cout<<t;
		tmp=(tmp*10+a[i]-'0')%b;
	}
	cout<<" "<<tmp;
	return 0;
}



1018 锤子剪刀布 (20 分)

#include <bits/stdc++.h>
using namespace std;
struct node{
	char name; int cnt=0;
};
map<char,node>ma1;
map<char,node>ma2;
bool cmp(pair<char,node> a,pair<char,node> b){
	if(a.second.cnt!=b.second.cnt) return a.second.cnt>b.second.cnt;
	return a.second.name<b.second.name;
}
int main(){
	int cnt1=0,cnt2=0,cnt3=0,cnt4=0,cnt5=0,cnt6=0;
	int n; cin>>n;
	ma1['C'].name='C',ma1['J'].name='J',ma1['B'].name='B';
	ma2['C'].name='C',ma2['J'].name='J',ma2['B'].name='B';
	while(n--){
		char a,b; cin>>a>>b;
		if(a==b){
			cnt2++,cnt5++;
		} else if(a=='C'&&b=='J'){
			cnt1++,cnt6++;
			ma1['C'].cnt++;
		} else if(a=='C'&&b=='B'){
			cnt3++,cnt4++;
			ma2['B'].cnt++;
		} else if(a=='J'&&b=='C'){
			cnt3++,cnt4++;
			ma2['C'].cnt++;
		} else if(a=='J'&&b=='B'){
			cnt1++,cnt6++;
			ma1['J'].cnt++;
		} else if(a=='B'&&b=='C'){
			cnt1++,cnt6++;
			ma1['B'].cnt++;
		} else {
			cnt3++,cnt4++; 
			ma2['J'].cnt++;
		}
	}
	cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;
	cout<<cnt4<<" "<<cnt5<<" "<<cnt6<<endl;
	vector<pair<char,node>>ve1(ma1.begin(),ma1.end());
	vector<pair<char,node>>ve2(ma2.begin(),ma2.end());
	sort(ve1.begin(),ve1.end(),cmp);
	sort(ve2.begin(),ve2.end(),cmp);
	cout<<ve1[0].second.name<<" "<<ve2[0].second.name<<endl;
	return 0;
}



1019 数字黑洞 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin>>s;
	if(s.size()!=4) s=string(4-s.size(),'0')+s;
	do{
		string b = s; sort(b.begin(),b.end());
		string a = b; reverse(a.begin(),a.end());
		s = to_string(stoi(a)-stoi(b));
		if(s.size()!=4) s=string(4-s.size(),'0')+s;
		cout<<a<<" - "<<b<<" = "<<s<<endl;
	}while(s!="6174"&&s!="0000");
	return 0;
}




1020 月饼 (25 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
struct node{
	double a,b,c;
}y[maxn];
bool cmp(node a,node b){
	return a.c>b.c;
}
int main(){
	int n,d; cin >> n >> d;
	for(int i=1; i<=n; i++){
		cin >> y[i].a;
	}
	for(int i=1; i<=n; i++){
		cin >> y[i].b; y[i].c = y[i].b/y[i].a;
	}
	sort(y+1,y+1+n,cmp);
	double ans = 0;
	for(int i=1; i<=n; i++){
		if(y[i].a<=d){
			d-=y[i].a; ans += y[i].b;
		} else {
			ans += y[i].c*d;
			break;
		}
	}
	printf("%.2lf",ans);
	return 0;
}



1021 个位数统计 (15 分)

#include <bits/stdc++.h>
using namespace std;
int num[15];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
			num[s[i]-'0']++;
		}
		for(int i=0; i<=9; i++){
			if(num[i]!=0){
				cout<<i<<":"<<num[i]<<endl;
			}
		}
	return 0;
}



1022 D进制的A+B (20 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c,d; cin>>a>>b>>d; c=a+b;
	vector<ll>ve;
	if(c==0){
		cout<<0; return 0;
	} else {
		while(c!=0){
			ve.push_back(c%d); c/=d;
		}
		for(int i=ve.size()-1; i>=0; i--){
			cout<<ve[i];
		}
	}
	return 0;
}



1023 组个最小数 (20 分)

#include <bits/stdc++.h>
using namespace std;
int a[15];
int main(){
	for(int i=0; i<10; i++){
		int x; cin>>x; a[i]=x;
	}
	for(int i=1; i<10; i++){
		if(a[i]!=0){
			cout<<i; a[i]--; break;
		}
	}
	for(int i=1; i<=a[0]; i++){
		cout<<0;
	}
	for(int i=1; i<10; i++){
		if(a[i]!=0){
			for(int j=1; j<=a[i]; j++){
				cout<<i;
			}
		}
	}
	return 0;
}



1024 科学计数法 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; getline(cin,s);
	char op[3]; int cnt=0; int p=0;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='+'||s[i]=='-'){
			op[cnt++]=s[i]; 
			if(cnt==2){
				p=i; break;
			}
		}
	}
	if(op[0]=='-') cout<<"-";
	vector<int>ve;
	for(int i=0; i<p; i++){
		if(isdigit(s[i])){
			ve.push_back(s[i]-'0');
		}
	}
	int num=stoi(s.substr(p+1,s.size()-p-1));
	if(op[1]=='+'){
		int x = num+1-(int)ve.size();
		for(int i=0; i<ve.size(); i++){
			if(x<0 && i-x==ve.size())cout<<".";
			cout<<ve[i];
		}
		if(x>0)cout<<string(x,'0');
	} else {
		cout<<"0.";
		for(int i=1; i<num; i++) cout<<0;
		for(int i=0; i<ve.size(); i++) cout<<ve[i];
	}
	return 0;
}



#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int main(){
	char op, a[maxn]={0}; int z;
	scanf("%c%c.%[0-9]E%d", &op, &a[0], a+1, &z);
	if(op=='-') putchar('-');
	if(z<0){
		printf("0.");
		for(int i=0; i<-z-1; i++) putchar('0');
		printf("%s", a);
	} else {
		for(int i=0; a[i] || i<=z; i++){
			if(i==z+1) putchar('.');
			putchar(a[i]?a[i]:'0');
		}
	}
	return 0;
} 




1025 反转链表 (25 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct node{
	int address,data,next;
}li[maxn]; 
int main(){
	int begin,n,k; cin >> begin >> n >> k;
	int cnt=0;
	for(int i=1; i<=n; i++){
		int a; cin >>a;
		li[a].address = a; cin >> li[a].data >> li[a].next;
	}
	vector<node>ve,ans;
	for(int i=begin; i!=-1; i=li[i].next){
		ve.push_back(li[i]); cnt++;
		if(cnt == k){
			reverse(ve.begin(),ve.end());
			ans.insert(ans.end(),ve.begin(),ve.end());
			ve.clear(); cnt=0;
		}
	}
	ans.insert(ans.end(),ve.begin(),ve.end());
	for(int i=0; i<ans.size(); i++){
		printf("%05d %d ",ans[i].address,ans[i].data);
		if(i!=ans.size()-1) printf("%05d",ans[i+1].address);
		else printf("-1");
		cout<<endl;
	}
	return 0;
}



1026 程序运行时间 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int c1,c2; cin>>c1>>c2;
	int hh,mm,ss;
	ss=(int)(1.0*(c2-c1)/100+0.5);
	mm=ss/60; ss%=60;
	hh=mm/60; mm%=60;
	printf("%02d:%02d:%02d",hh,mm,ss);
	return 0;
}



1027 打印沙漏 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; char c; cin>>n>>c;
	int cur=0,ans=0;
	for(int i=0; i<=1000; i++){
		if(1+2*i*(i+2)>n){
			cur=i-1; ans=1+2*(i-1)*(i+1); break;
		}
		if(i+2*i*(i+2)==n){
			cur=i; ans=1+2*i*(i+2); break;
		}
	}
	for(int i=cur; i>=1; i--){
		for(int j=1; j<=cur-i; j++) cout<<" ";
		for(int j=1; j<=2*i+1; j++) cout<<c;
// 		for(int j=1; j<=cur-i; j++) cout<<" ";
		cout<<endl;
	}
	for(int i=1; i<=cur; i++) cout<<" ";
	cout<<c;
// 	for(int i=1; i<=cur; i++) cout<<" ";
	cout<<endl;
	for(int i=1; i<=cur; i++){
		for(int j=1; j<=cur-i; j++) cout<<" ";
		for(int j=1; j<=2*i+1; j++) cout<<c;
// 		for(int j=1; j<=cur-i; j++) cout<<" ";
		cout<<endl;
	}
	cout<<n-ans;
	return 0;
} 




1028 人口普查 (20 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct node{
	string name; int yy,mm,dd;
};
vector<node>ve;
bool cmp(node a,node b){
	if(a.yy!=b.yy) return a.yy<b.yy;
	if(a.mm!=b.mm) return a.mm<b.mm;
	return a.dd<b.dd;
}
int main(){
	int n; scanf("%d",&n);
	int cnt=0,yy,mm,dd; string name;
	for(int i=1; i<=n; i++){
		cin>>name;
		scanf("%d/%d/%d",&yy,&mm,&dd);
		if(yy<1814 || (yy==1814 && mm<9) || (yy==1814 && mm==9 && dd<6)) continue;
		if(yy>2014 || (yy==2014 && mm>9) || (yy==2014 && mm==9 && dd>6)) continue;
		cnt++; ve.push_back(node{name,yy,mm,dd});
	}
	sort(ve.begin(),ve.end(),cmp);
	if(cnt!=0) cout<<cnt<<" "<<ve[0].name<<" "<<ve[cnt-1].name;
	else cout<<0;  //pat教窝做人
	return 0;
} 



#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, cnt = 0; cin>>n;
    string name, birth, maxname, minname, maxbirth = "1814/09/06", minbirth = "2014/09/06";
    for (int i = 0; i < n; i++) {
        cin >> name >> birth;
        if (birth >= "1814/09/06" && birth <= "2014/09/06") {
            cnt++;
            if (birth >= maxbirth) {
                maxbirth = birth;
                maxname = name;
            }
            if (birth <= minbirth) {
                minbirth = birth;
                minname = name;
            }
        }
    }
    cout << cnt;
    if (cnt != 0) cout << " " << minname << " " << maxname;
    return 0;
}




1029 旧键盘 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s1,s2,ans;
	cin>>s1>>s2;
	for(int i=0; i<s1.size(); i++){
		if(s2.find(s1[i])==string::npos && ans.find(toupper(s1[i]))==string::npos){
			ans+=toupper(s1[i]);
		}
	}
	cout<<ans;
    return 0;
}


1030 完美数列 (25 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn];
int main(){
	ll n,p; scanf("%lld %lld",&n,&p);
	for(int i=0; i<n; i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	ll max=0;
	for(int i=0; i<n; i++){
		ll tmp = p*a[i];
		ll t = upper_bound(a,a+n,tmp)-a;
		if(t-i > max) max = t-i;
//		cout<<tmp<<" "<<t<<" "<<max<<endl;
	}
	printf("%lld",max);
	return 0;
}



#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
int main(){
	LL n, p; cin>>n>>p;
	vector<int>a(n);
	for(int i = 0;i < n; i++)cin>>a[i];
	sort(a.begin(),a.end());
	LL ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+ans; j < n; j++){//+ans剪枝
			if(a[j]<=a[i]*p)
				ans = max(ans, (LL)j-i+1);
			else break;
		}
	}
	cout<<ans;
	return 0;
}



1031 查验身份证 (15 分)

#include <bits/stdc++.h>
using namespace std;
int jy[11]={1,0,10,9,8,7,6,5,4,3,2};
int qz[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int main(){
	int n; cin>>n; bool ok=1;
	while(n--){
		string s; cin>>s;
		bool is=1;
		int cnt=0;
		for(int i=0; i<s.size()-1; i++){
			if(!isdigit(s[i])){
				is=0; ok=0; cout<<s<<endl; break;
			}
			cnt+=qz[i]*(s[i]-'0');
		}
		if(!is) continue;
		cnt=cnt%11;
		if(cnt==2){
			if((s[s.size()-1])!='X'){ //字符
				cout<<s<<endl; ok=0;
			}
		} else {
			if((s[s.size()-1]-'0')!=jy[cnt]){ //字符数字转纯数字
				cout<<s<<endl; ok=0;
			}
		}
	}
	if(ok==1) cout<<"All passed"<<endl;
	return 0;
} 


1032 挖掘机技术哪家强 (20 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
struct node{
	int id,cnt=0;
};
bool cmp(node a,node b){
	return a.cnt<b.cnt;
}
int main(){
	vector<node>ve(maxn);
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		int a,b; cin>>a>>b;
		ve[a].id=a,ve[a].cnt+=b;
	}
	sort(ve.begin(),ve.end(),cmp);
	cout<<ve[maxn-1].id<<" "<<ve[maxn-1].cnt;
	return 0;
}




1033 旧键盘打字 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s1,s2; getline(cin,s1); getline(cin,s2);
	for(int i=0; i<s2.size(); i++){
		if(s1.find(toupper(s2[i]))!=string::npos) continue;
		if(s1.find('+')!=string::npos && isupper(s2[i])) continue;
		cout<<s2[i];
	}
	return 0;
}



1034 有理数四则运算 (20 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
void prin(ll n,ll m){
	if(n*m==0){
		printf("%s",m==0?"Inf":"0"); return ;
	}
	int ok=0;
	if((n<0 && m>0) || (n>0 && m<0)) ok=1;
	if(ok) cout<<"(-";
	
	n=abs(n),m=abs(m);
	ll x=n/m, r=n%m;
	if(x!=0) cout<<x;
	if(r==0){
		if(ok) cout<<")"; return ;
	}
	if(x!=0) cout<<" ";
	n=r;
	ll t = gcd(n,m);
	n/=t,m/=t;
	cout<<n<<"/"<<m;
	if(ok) cout<<")";
}
int main(){
	ll a,b,c,d; scanf("%lld/%lld %lld/%lld",&a,&b,&c,&d);
	prin(a,b); cout<<" + "; prin(c,d); cout<<" = "; prin(a*d+b*c,b*d); cout<<endl;
	prin(a,b); cout<<" - "; prin(c,d); cout<<" = "; prin(a*d-b*c,b*d); cout<<endl;
	prin(a,b); cout<<" * "; prin(c,d); cout<<" = "; prin(a*c,b*d); cout<<endl;
	prin(a,b); cout<<" / "; prin(c,d); cout<<" = "; prin(a*d,b*c); cout<<endl;
	return 0;
}



1036 跟奥巴马一起编程 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; char c; cin>>n>>c;
	int hang=(int)(1.0*n/2+0.5);
	for(int i=1; i<=hang; i++){
		if(i==1||i==hang){
			for(int j=1; j<=n; j++) cout<<c;
		} else {
			cout<<c;
			for(int j=1; j<=n-2; j++) cout<<" ";
			cout<<c;
		}
		cout<<endl;
	}
	return 0;
} 



1037 在霍格沃茨找零钱 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x,y,z; scanf("%d.%d.%d %d.%d.%d",&a,&b,&c,&x,&y,&z);
	int xx=a*17*29+b*29+c,yy=x*17*29+y*29+z;
	if(xx>yy) cout<<"-";
	int zz=max(xx,yy)-min(xx,yy);
	vector<int>ve;
	ve.push_back(zz%29); zz/=29;
	ve.push_back(zz%17); zz/=17;
	ve.push_back(zz);
	for(int i=2; i>=0; i--){
		if(i!=2) cout<<".";
		cout<<ve[i];
	}
	return 0;
}



1038 统计同成绩学生 (20 分)

#include <bits/stdc++.h>
using namespace std;
int a[110];
int main(){
	int n; scanf("%d",&n);
	for(int i=1; i<=n; i++){
		int x; scanf("%d",&x); a[x]++;
	}
	int k; cin>>k;
	for(int i=1; i<=k; i++){
		if(i!=1) cout<<" ";
		int x; scanf("%d",&x); cout<<a[x];
	}
	return 0;
}



1039 到底买不买 (20 分)

#include <bits/stdc++.h>
using namespace std;
int a[100];
int main(){
	string s1,s2; cin>>s1>>s2;
	int cnt=0;
	for(int i=0; i<s1.size(); i++){
		if(isdigit(s1[i])){
			a[s1[i]-'0']++;
		} else if(islower(s1[i])){
			a[s1[i]-'a'+10]++;
		} else {
			a[s1[i]-'A'+50]++;
		}
	}
	for(int i=0; i<s2.size(); i++){
		if(isdigit(s2[i])){
			if(a[s2[i]-'0']>0){
				a[s2[i]-'0']--; continue;
			} else cnt++;
		} else if(islower(s2[i])){
			if(a[s2[i]-'a'+10]>0){
				a[s2[i]-'a'+10]--; continue;
			} else cnt++;
		} else {
			if(a[s2[i]-'A'+50]>0){
				a[s2[i]-'A'+50]--; continue;
			} else cnt++;
		}
	}
	if(cnt==0){
		cout<<"Yes"<<" "<<s1.size()-s2.size();
	} else cout<<"No"<<" "<<cnt;
	return 0;
} 



#include <iostream>
using namespace std;
int book[256];
int main() {
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.length(); i++)
        book[a[i]]++;
    int result = 0;
    for (int i = 0; i < b.length(); i++) {
        if (book[b[i]] > 0)
            book[b[i]]--;
        else
            result++;
    }
    if(result != 0)
        printf("No %d", result);
    else
        printf("Yes %d", a.length() - b.length());
    return 0;
}



1040 有几个PAT (25 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
const int mod = 1000000007;
int t[maxn], at[maxn];
int main(){
	string s; cin>>s;
	int ans=0;
	for(int i=s.size()-1; i>=0; i--){
		t[i]=t[i+1]; at[i]=at[i+1];
		if(s[i]=='P') ans = (ans+at[i])%mod;
		if(s[i]=='A') at[i] = (at[i]+t[i])%mod;
		if(s[i]=='T') t[i]++;
	}
	cout << ans%mod;
	return 0;
}



1041 考试座位号 (15 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1010;
struct node{
	string id; int ks;
}stu[maxn];
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		string s; int sj,ks; cin>>s>>sj>>ks;
		stu[sj].id=s,stu[sj].ks=ks;
	}
	int m; cin>>m;
	for(int i=1; i<=m; i++){
		int a; cin>>a;
		cout<<stu[a].id<<" "<<stu[a].ks<<endl;
	}
	return 0;
} 



1042 字符统计 (20 分)

#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main() {
    string s;
    getline(cin, s);
    int a[26] = {0};
    for (int i = 0; i < s.length(); i++)
        s[i] = tolower(s[i]);
    for (int i = 0; i < s.length(); i++)
        if (islower(s[i])) a[s[i] - 'a']++;
    int max = a[0], t = 0;
    for (int i = 1; i < 26; i++) {
        if (a[i] > max) {
            max = a[i];
            t = i;
        }
    }
    printf("%c %d", t + 'a', max);
    return 0;
}


1043 输出PATest (20 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int main(){
	int cnt1=0,cnt2=0,cnt3=0,cnt4=0,cnt5=0,cnt6=0;
	string s; cin>>s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='P') cnt1++;
		if(s[i]=='A') cnt2++;
		if(s[i]=='T') cnt3++;
		if(s[i]=='e') cnt4++;
		if(s[i]=='s') cnt5++;
		if(s[i]=='t') cnt6++;
	}
	int ok=1;
	while(1){
		ok=0;
		if(cnt1>0){
			cout<<"P"; cnt1--; ok=1;
		}
		if(cnt2>0){
			cout<<"A"; cnt2--; ok=1;
		}
		if(cnt3>0){
			cout<<"T"; cnt3--; ok=1;
		}
		if(cnt4>0){
			cout<<"e"; cnt4--; ok=1;
		}
		if(cnt5>0){
			cout<<"s"; cnt5--; ok=1;
		}
		if(cnt6>0){
			cout<<"t"; cnt6--; ok=1;
		}
		if(!ok) break;
	}
	return 0;
} 



1044 火星数字 (20 分)

#include <bits/stdc++.h>
using namespace std;
string a[] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[] = {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string tohuo(string s){
	int t = stoi(s);
	int aa = t%13, bb = t/13;
	if(bb == 0) return a[aa];
	if(aa == 0) return b[bb];
	return b[bb]+" "+a[aa];
}
int todi(string s){
	if(s.find(" ") == string::npos){
		for(int i=0; i<13; i++){
			if(a[i] == s) return i;
		}
		for(int i=0; i<13; i++){
			if(b[i] == s) return 13*i;
		}
	} else {
		int t = 0;
		string t1 = s.substr(0,3), t2 = s.substr(4,3);
		for(int i=0; i<13; i++){
			if(b[i] == t1){
				t += 13*i; break;
			}
		}
		for(int i=0; i<13; i++){
			if(a[i] == t2){
				t += i; return t;
			}
		}
	}
}
int main(){
	int n; cin>>n; cin.get();
	while(n--){
		string s; getline(cin,s);
		if(isdigit(s[0])) cout << tohuo(s) << endl;
		else cout << todi(s) << endl;
	}
	return 0;
}



1045 快速排序 (25 分)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
const int inf = 1e9+10;
int mx[maxn],mi[maxn],a[maxn];
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		mx[i]=max(mx[i-1],a[i-1]);
		mi[i]=inf;
	}
	mi[n]=inf;
	for(int i=n-1; i>=1; i--){
		mi[i]=min(mi[i+1],a[i+1]);
	}
	int cnt=0; vector<int>ve;
	for(int i=1; i<=n; i++){
		if(mx[i]<a[i] && mi[i]>a[i]){
			cnt++; ve.push_back(a[i]);
		}
	}
	cout<<cnt<<endl;
	if(cnt==0) cout<<endl;
	else {
		for(int i=0; i<ve.size(); i++){
			if(i!=0) cout<<" "; cout<<ve[i];
		}
	}
	return 0;
}




1046 划拳 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int cnt1=0,cnt2=0;
	int n; cin>>n;
	while(n--){
		int a,b,c,d; cin>>a>>b>>c>>d;
		if(b==a+c&&d!=a+c){
			cnt2++;
		}
		if(d==a+c&&b!=a+c){
			cnt1++;
		}
	}
	cout<<cnt1<<" "<<cnt2<<endl;
	return 0;
} 




1047 编程团体赛 (20 分)

#include <bits/stdc++.h>
using namespace std;
int a[1010];
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		int x,y,z; scanf("%d-%d %d",&x,&y,&z);
		a[x]+=z;
	}
	int max=a[1],p=1;
	for(int i=1; i<1010; i++){
		if(a[i]>max){
			max=a[i]; p=i;
		}
	}
	cout<<p<<" "<<max;
	return 0;
} 



1048 数字加密 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s1,s2; cin>>s1>>s2;
	if(s1.size()>s2.size()) s2=string(s1.size()-s2.size(),'0')+s2;
	else if(s1.size()<s2.size()) s1=string(s2.size()-s1.size(),'0')+s1;
	bool ok=1;
	vector<char>ve;
	for(int i=s1.size()-1; i>=0; i--){
		if(ok){
			int t=(s2[i]-'0'+s1[i]-'0')%13;
			if(t==10) ve.push_back('J');
			else if(t==11) ve.push_back('Q');
			else if(t==12) ve.push_back('K');
			else ve.push_back((char)(t+'0'));
			ok=0;
		} else {
			int t=(s2[i]-'0'-(s1[i]-'0'));
			if(t<0) t+=10;
			if(t==10) ve.push_back('J');
			else if(t==11) ve.push_back('Q');
			else if(t==12) ve.push_back('K');
			else ve.push_back((char)(t+'0'));
			ok=1;
		}
	}
	for(int i=ve.size()-1; i>=0; i--){
		cout<<ve[i];
	}
	return 0;
}



1049 数列的片段和 (20 分)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n; cin>>n;
	ll ans=0;
	for(int i=1; i<=n; i++){
		double tmp; cin>>tmp;
		ans+=(ll)(1000*tmp)*i*(n-i+1);
	} 
	printf("%.2lf",ans/1000.0);
	return 0;
}


1050 螺旋矩阵 (25 分)

#include<bits/stdc++.h>
using namespace std;
const int maxn=10010;
int g[maxn][maxn];
int main(){
	int N; cin>>N;
	vector<int>ve;
	for(int i=1; i<=N; i++){
		int x; cin>>x; ve.push_back(x);
	}
	sort(ve.begin(),ve.end()); reverse(ve.begin(),ve.end());
	int m = (int)ceil(sqrt(1.0*N));
	while(N%m!=0) m++;
	if(N==1){
		cout<<ve[0]<<endl; return 0;
	}
	int n=N/m, i=1, j=1, now=0;
	int a=1, b=1, c=n, d=m;
	while(now < N){
		while(now < N && j<c){
			g[i][j]=ve[now++]; j++;
		}
		while(now < N && i<d){
			g[i][j]=ve[now++]; i++;
		}
		while(now < N && j>b){
			g[i][j]=ve[now++]; j--;
		}
		while(now < N && i>a){
			g[i][j]=ve[now++]; i--;
		}
		a++,b++,c--,d--;
		i++,j++;
		if(now == N-1) g[i][j]=ve[now++];
	}
	for(int i=1; i<=m; i++){
		for(int j=1; j<=n; j++){
			cout<<g[i][j];
			if(j!=n) cout<<" "; else cout<<endl;
		}
	}
	return 0;
}



1051 复数乘法 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	double r1,p1,r2,p2; cin>>r1>>p1>>r2>>p2;
	double a,b;
	a=r1*r2*cos(p1)*cos(p2)-r1*r2*sin(p1)*sin(p2);
	b=r1*r2*cos(p1)*sin(p2)+r1*r2*cos(p2)*sin(p1);
	if(a>-0.005&&a<0) printf("0.00"); else printf("%.2lf",a);
	if(b>=0) printf("+%.2lfi",b);
	else if(b>-0.005) printf("+0.00i");
	else printf("%.2lfi",b);
	return 0;
} 



1052 卖个萌 (20 分)

#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<string>ss,yy,kk;
	string aa,bb,cc;
	getline(cin,aa); getline(cin,bb); getline(cin,cc);
	int t=0;
	for(int i=0; i<aa.size(); i++){
		if(aa[i]=='[') t=i;
		if(aa[i]==']') ss.push_back(aa.substr(t+1,i-t-1));
	}
	t=0;
	for(int i=0; i<bb.size(); i++){
		if(bb[i]=='[') t=i;
		if(bb[i]==']') yy.push_back(bb.substr(t+1,i-t-1));
	}
	t=0;
	for(int i=0; i<cc.size(); i++){
		if(cc[i]=='[') t=i;
		if(cc[i]==']') kk.push_back(cc.substr(t+1,i-t-1)); 
	}
	int k; cin>>k;
	while(k--){
		int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
		if(a<1||b<1||c<1||d<1||e<1||a>ss.size()||b>yy.size()||c>kk.size()||d>yy.size()||e>ss.size()){
			cout<<"Are you kidding me? @\\/@"<<endl; continue;
		}
		cout<<ss[a-1]<<"("<<yy[b-1]<<kk[c-1]<<yy[d-1]<<")"<<ss[e-1]<<endl;
	}
	return 0;
}



1053 住房空置率 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,d; double e;
	cin>>n>>e>>d;
	int cnt1=0,cnt2=0;
	for(int i=1; i<=n; i++){
		int k,cnt=0; cin>>k;
		for(int j=1; j<=k; j++){
			double x; cin>>x; if(x<e) cnt++;
		}
		if(cnt>k/2 && k>d) cnt2++;
		else if(cnt>k/2) cnt1++;
	}
	printf("%.1lf%% %.1lf%%",(double)cnt1*100/n,(double)cnt2*100/n);
	return 0;
}


1054 求平均值 (20 分)

#include <bits/stdc++.h>
using namespace std;
bool pd(string tmp){
	for(int j=0; j<tmp.size(); j++){
		if(isalpha(tmp[j])){
			return 0;
		}
	}
	if(tmp.find('.')!=string::npos){
		int j=tmp.find('.'); j++;
		while(j<tmp.size()){
			if(j=='.' || j-tmp.find('.')>2){
				return 0;
			}
			j++;
		}
	}
	double t=stof(tmp);
	if(t<-1000 || t>1000){
		return 0;
	}
	return 1;
}
int main(){
	int n; cin>>n;
	int cnt=0;
	double sum=0;
	for(int i=1; i<=n; i++){
		string tmp; cin >> tmp;
		if(pd(tmp)) sum+=stof(tmp), cnt++;
		else cout<<"ERROR: "<<tmp<<" is not a legal number"<<endl;
	}
	cout << "The average of " << cnt;
	if (cnt == 1)						//看清题意
		cout << " number is ";
	else
		cout << " numbers is ";
	if (cnt)
		printf("%.2lf", (double)sum / cnt);
	else
		cout << "Undefined";
	return 0;
}



1055 集体照 (25 分)

#include <bits/stdc++.h>
using namespace std;
struct node{
	string name; int h;
};
bool cmp(node a, node b){
	if(a.h != b.h) return a.h > b.h;
	return a.name < b.name;
}
int main(){
	int n,k; cin >> n >> k;
	int row = k, t = 0, m;
	vector<node>ve(n);
	for(int i = 0; i < n; i++){
		cin >> ve[i].name >> ve[i].h;
	}
	sort(ve.begin(), ve.end(), cmp);
	while(row){
		if(row == k){
			m = n - (n / k) * (k - 1);
		} else {
			m = n / k;
		}
		vector<string>ans(m);
		ans[m / 2] = ve[t].name;
		int j = m / 2 - 1;
		for(int i = t + 1; i < t + m ; i += 2 ){
			ans[j--] = ve[i].name;
		}
		j = m / 2 + 1;
		for(int i = t + 2; i < t + m; i += 2 ){
			ans[j++] = ve[i].name;
		}
		for(int i=0; i<ans.size(); i++){
			if(i!=0) cout<<" "; cout<<ans[i];
		}
		cout<<endl;
		t += m; row--;
	}
	return 0;
}



1056 组合数的和 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n;
	int cnt=0;
	for(int i=1; i<=n; i++){
		int x; cin>>x; cnt+=x;
	}
	int ans=cnt*(n-1)*11;
	cout<<ans<<endl;
	return 0;
} 



1057 数零壹 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; getline(cin,s);
	int cnt = 0;
	for(int i=0; i<s.size(); i++){
		if(isalpha(s[i])){
			s[i] = tolower(s[i]);
			cnt += s[i] - 'a' + 1;
		}
	}
	if(cnt == 0){
		cout << "0 0"<<endl; return 0;
	}
	int cnt0 = 0, cnt1 = 0;
	while(cnt){
		if(cnt % 2 == 1) cnt1++; else cnt0++;
		cnt /= 2;
	}
	cout << cnt0 <<" " << cnt1 <<endl; 
	return 0;
}



1058 选择题 (20 分)

#include <bits/stdc++.h>
using namespace std;
int sc[110], cnt[110];
string as[110];
int main(){
	int n,m; cin>>n>>m;
	for(int i=1; i<=m; i++){
		int x,y; cin>>sc[i]>>x>>y;
		for(int j=1; j<=y; j++){
			char c; cin>>c;
			as[i]+=c;
		}
	}
	getchar();
	int mx=0;
	for(int i=1; i<=n; i++){
		int fen=0;
		for(int j=1; j<=m; j++){
			getchar();
			int kk; cin>>kk; string t="";
			for(int k=1; k<=kk; k++){
				char c; cin>>c; t+=c;
			}
			if(t==as[j]) fen+=sc[j];
			else {
				cnt[j]++;
				if(cnt[j]>mx) mx=cnt[j];
			}
			getchar(); getchar();
		}
		cout<<fen<<endl;
	}
	if(mx==0){
		cout<<"Too simple"<<endl; return 0; 
	}
	cout<<mx;
	for(int i=1; i<=m; i++){
		if(cnt[i]==mx) cout<<" "<<i;
	}
	return 0;
}


1059 C语言竞赛 (20 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int pm[maxn];
bool pd(int x){
	if(x==0 || x==1) return 0;
	for(int i=2; i<=sqrt(x)+1; i++){
		if(x%i==0) return 0;
	}
	return 1;
}
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		int x; cin>>x; pm[x]=i;
	}
	int k; cin>>k;
	set<int>se;
	for(int i=1; i<=k; i++){
		int x; cin>>x;
		if(se.find(x)!=se.end()){
			printf("%04d: Checked\n",x); continue;
		}
		if(x<0 || x>9999 || pm[x]==0){
			printf("%04d: Are you kidding?\n",x); continue;
		}
		se.insert(x);
		if(pm[x]==1) printf("%04d: Mystery Award\n",x);
		else if(pd(pm[x])) printf("%04d: Minion\n",x);
		else printf("%04d: Chocolate\n",x);
	}
	return 0;
}


1060 爱丁顿数 (25 分)

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
    int i;
	for(i=1; i<=n; i++){
		if(i>=a[i]){
			break;
		}
	}
    cout<<i-1;
	return 0;
}



1061 判断题 (15 分)

#include <bits/stdc++.h>
using namespace std;
int cj[110];
int da[110];
int main(){
	int n,m; cin>>n>>m;
	for(int i=1; i<=m; i++){
		cin>>cj[i];
	}
	for(int i=1; i<=m; i++){
		cin>>da[i];
	}
	while(n--){
		int cnt=0;
		for(int i=1; i<=m; i++){
			int x; cin>>x;
			if(x==da[i]) cnt+=cj[i];
		}
		cout<<cnt<<endl;
	}
	return 0;
} 


1066 图像过滤 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,n,a,b,th; cin>>m>>n>>a>>b>>th;
	for(int i=1; i<=m; i++){
		for(int j=1; j<=n; j++){
			int x; scanf("%d",&x);
			if(a<=x&&x<=b){
				printf("%03d",th);
			} else printf("%03d",x);
			if(j!=n) printf(" ");
		}
		cout<<endl;
	} 
	return 0;
} 



1069 微博转发抽奖 (20 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,n,f; cin>>m>>n>>f;
	set<string>se;
	string s; bool ok=0;
	int cnt=0;
	for(int i=1; i<=m; i++){
		cin>>s;
		if(i<f) continue;
		if(i==f){
			ok=1; cout<<s<<endl; se.insert(s); continue;
		}
		if(se.find(s)!=se.end()) continue;
		cnt++;
		if(cnt%n==0){
			se.insert(s); cout<<s<<endl;
		}
	}
	if(!ok) cout<<"Keep going..."<<endl;
	return 0;
}




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <map>
using namespace std;
int main() {
    int m, n, s;
    scanf("%d%d%d", &m, &n, &s);
    string str;
    map<string, int> mapp;
    bool flag = false;
    for (int i = 1; i <= m; i++) {
        cin >> str;
        if (mapp[str] == 1) s = s + 1;
        if (i == s && mapp[str] == 0) {
            mapp[str] = 1;
            cout << str << endl;
            flag = true;
            s = s + n;
        }
    }
    if (flag == false) cout << "Keep going...";
    return 0;
}


1071 小赌怡情 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int cnt,k; cin>>cnt>>k;
	for(int i=1; i<=k; i++){
		int n1,b,t,n2; cin>>n1>>b>>t>>n2;
		if(t>cnt){
			cout<<"Not enough tokens.  Total = "<<cnt<<"."<<endl; continue;
		}
		if(n1>n2&&b==0){
			cnt+=t; cout<<"Win "<<t<<"!  Total = "<<cnt<<"."<<endl;
		} else if(n1>n2&&b==1){
			cnt-=t; cout<<"Lose "<<t<<".  Total = "<<cnt<<"."<<endl;
		} else if(n1<n2&&b==0){
			cnt-=t; cout<<"Lose "<<t<<".  Total = "<<cnt<<"."<<endl;
		} else {
			cnt+=t; cout<<"Win "<<t<<"!  Total = "<<cnt<<"."<<endl;
		}
		if(cnt<=0){
			cout<<"Game Over."<<endl; break;
		}
	}
	return 0;
} 



1076 Wifi密码 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n; cin.get();
	for(int i=1; i<=n; i++){
		string s; getline(cin,s);
		int pos=s.find("-T");
		if(s[pos-1]=='A'){
			cout<<"1";
		} else if(s[pos-1]=='B'){
			cout<<"2";
		} else if(s[pos-1]=='C'){
			cout<<"3";
		} else cout<<"4";
	}
	return 0;
} 



1081 检查密码 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n; cin.get();
	while(n--){
		string s; getline(cin,s); int ok=1;
		if(s.size()<6){
			cout<<"Your password is tai duan le."<<endl; continue;
		}
		for(int i=0; i<s.size(); i++){
			if(!isalnum(s[i])&&s[i]!='.'){
				ok=0; cout<<"Your password is tai luan le."<<endl; break;
			}
		}
		if(!ok) continue;
		bool zm=0,sz=0;
		for(int i=0; i<s.size(); i++){
			if(isdigit(s[i])) sz=1;
			if(isalpha(s[i])) zm=1;
		}
		if(!sz){
			cout<<"Your password needs shu zi."<<endl;continue;
		}
		if(!zm){
			cout<<"Your password needs zi mu."<<endl;continue;
		}
		cout<<"Your password is wan mei."<<endl;
	}
	return 0;
} 



1086 就不告诉你 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b; cin>>a>>b;
	int c=a*b;
	string s=to_string(c);
	for(int i=s.size()-1; i>=0; i--){
		if(i==s.size()-1&&s[i]=='0'){
			int j=i;
			while(j>=0&&s[j]=='0') j--;
			i=++j;
		} else cout<<s[i];
	}
	return 0;
} 



1091 N-自守数 (15 分)

#include <bits/stdc++.h>
using namespace std;
int main(){
	int m; cin>>m;
	while(m--){
		int ok=0;
		int x; cin>>x;
		int pf=x*x; string s=to_string(x);
		for(int i=1; i<=9; i++){
			string tmp=to_string(i*pf);
			if(tmp.substr(tmp.size()-s.size(),s.size())==s){
				ok=1; cout<<i<<" "<<i*pf<<endl; break;
			}
		}
		if(!ok) cout<<"No"<<endl;
	}
	return 0;
} 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值