pat乙级1056-1060

Posted suying

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pat乙级1056-1060相关的知识,希望对你有一定的参考价值。

//1
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int sum=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) continue;
else sum+=a[i]*10+a[j];
}
}
printf("%d",sum);
return 0;
}
//2
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
int sum=0;
for(int i=0;i<s.length();i++){
if(isalpha(s[i])){
if(s[i]>=‘A‘&&s[i]<=‘Z‘) sum+=s[i]+32-‘a‘+1;
if(s[i]>=‘a‘&&s[i]<=‘z‘) sum+=s[i]-‘a‘+1;
}
}
int k=0,p=0,q=0;
int m[100000];
while(sum){
m[k++]=sum%2;
if(m[k-1]==0) p++;
if(m[k-1]==1) q++;
sum/=2;
}
printf("%d %d",p,q);
return 0;
}
//3
#include<bits/stdc++.h>
using namespace std;
struct node{
int score;
int right;
char right_cnt[6];
int wrong;
};
int main(){
int n,m;
cin>>n>>m;
node q[m];
for(int i=0;i<m;i++){
int cnt,k=0;
char c;
scanf("%d %d %d",&q[i].score,&cnt,&q[i].right);
q[i].wrong=0;
while((c=getchar())!=‘ ‘){
if(isalpha(c)) q[i].right_cnt[k++]=c;
}
q[i].right_cnt[k]=‘‘;
}

int grad[n],t=0,max_error=0;
for(int i=0;i<n;i++){
grad[i]=0;
for(int j=0;j<m;j++){
int cnt,p=0;
char c,choose[6];
scanf("(%d",&cnt);
while((c=getchar())!=‘)‘){
if(isalpha(c)) choose[p++]=c;
}
choose[p]=‘‘;
if(cnt==q[j].right&&strcmp(choose,q[j].right_cnt)==0){
grad[i]+=q[j].score;
}else{
q[j].wrong++;
}
if(q[j].wrong>max_error) max_error=q[j].wrong;
getchar();
}
}
for(int i=0;i<n;i++)
printf("%d ",grad[i]);
if(max_error==0){
printf("Too simple");
}else{
printf("%d",max_error);
for(int i=0;i<m;i++){
if(q[i].wrong==max_error)
printf(" %d",i+1);
}
}
return 0;
}
//4
//1)
#include<stdio.h>
int isprime(int a){
if(a==1) return 0;
for(int i=2;i*i<=a;i++){
if(a%i==0) return 0;
}
return 1;
}
int main(){
int award[10000]={0},n,k,id;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&id);
if(i==0) award[id]=1;
else if(isprime(i+1)) award[id]=2;
else award[id]=3;
}
scanf("%d",&k);
for(int i=0;i<k;i++){
scanf("%d",&id);
switch(award[id]){
case 0: printf("%04d: Are you kidding? ",id); break;
case 1: printf("%04d: Mystery Award ",id); award[id]=4;break;
case 2: printf("%04d: Minion ",id); award[id]=4;break;
case 3: printf("%04d: Chocolate ",id); award[id]=4;break;
case 4: printf("%04d: Checked ",id); break;
}
}
return 0;
}
//2)
#include<stdio.h>
int isprime(int a){
if(a==1) return 0;
for(int i=2;i*i<=a;i++)
if(a%i==0) return 0;
return 1;
}
int main(){
int n;
scanf("%d",&n);
int a[n][2];
for(int i=0;i<n;i++){
scanf("%d",&a[i][0]);
a[i][1]=0;
}
int p,q,t=0;
scanf("%d",&p);
for(int i=0;i<p;i++){
scanf("%d",&q);
for(int j=0;j<n;j++){
if(q==a[j][0]){
t++;
if(j==0){
if(a[0][1]==0){
printf("%04d: Mystery Award ",q);
a[0][1]=1;
break;}
if(a[0][1]==1){
printf("%04d: Checked ",q);
break;}
}
else if(isprime(j+1)){
if(a[j][1]==0){
printf("%04d: Minion ",q);
a[j][1]=1;
break; }
if(a[j][1]==1){
printf("%04d: Checked ",q);
break; }
}else{
if(a[j][1]==0){
printf("%04d: Chocolate ",q);
a[j][1]=1;
break; }
if(a[j][1]==1){
printf("%04d: Checked ",q);
break; }
}

}
}
if(t==0){
printf("%04d: Are you kidding? ",q);
continue;
}
t=0;
}
return 0;
}
//5
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n); //sort默认排序从小到大
int t;
if(a[0]>n){
t=n;
}else{
for(int i=n-1;i>=0 ;i--){
if(a[i]<=n-i){
t=n-i-1;
break;
}
}
}
printf("%d",t);
return 0;
}
























































































































































































































以上是关于pat乙级1056-1060的主要内容,如果未能解决你的问题,请参考以下文章

PAT乙级-1002 写出这个数

pat可以直接考甲级吗

PAT——乙级1016

PAT乙级1040

PAT乙级1085-----PAT单位排行 (25分)

PAT乙级 1065. 单身狗(25) by Python