1041 考试座位号
#include
#include
using namespace std;
int main(){
string stu[1005][2];
string s1,s2;
int m,n,t;
cin>>n;
for(int i=0;i<n;i++){
cin>>s1>>t>>s2;
stu[t][0]=s1;
stu[t][1]=s2;
}
cin>>m;
for(int i=0;i<m;i++){
cin>>t;
cout<<stu[t][0]<<" "<<stu[t][1]<<endl;
}
return 0;
}
1042 字符统计
#include
#include
#include
using namespace std;
int main(void){
string s;
getline(cin,s);
int a[26]={0};
for(int i=0;i<s.size();i++){
s[i]=tolower(s[i]);
if(islower(s[i]))
a[s[i]-'a']++;
}
int m=a[0],n=0;
for(int i=0;i<26;i++){
if(a[i]>m){
m=a[i];
n=i;
}
}
printf("%c %d",'a'+n,m);
return 0;
}
1043 输出PATest
#include
using namespace std;
int main(void){
int map[128]={0};
int c;
while((c=cin.get())!=EOF) map[c]++;
while(map['P']>0||map['A']>0||map['T']>0||map['e']>0||map['s']>0||map['t']>0){
if(map['P']-->0) cout<<"P";
if(map['A']-->0) cout<<"A";
if(map['T']-->0) cout<<"T";
if(map['e']-->0) cout<<"e";
if(map['s']-->0) cout<<"s";
if(map['t']-->0) cout<<"t";
}
return 0;
}
1044 火星数字
#include
#include
using namespace std;
string a[13]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13]={"####","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string s;
void fun1(int t){
if(t/13) cout<<b[t/13];
if((t/13)&&(t%13)) cout<<" ";
if((t%13||t==0)) cout<<a[t%13];
}
void fun2(){
int t1=0,t2=0;
string s1=s.substr(0,3),s2;
if(s.size()>4) s2=s.substr(4,3);
for(int i=1;i<=12;i++){
if(s1==a[i]||s2==a[i]) t2=i;
if(s1==b[i]) t1=i;
}
cout<<t1*13+t2;
}
int main(){
int n;cin>>n;
getchar();
for(int i=0;i<n;i++){
getline(cin,s);
if(s[0]>='0'&&s[0]<='9')
fun1(stoi(s));
else
fun2();
cout<<endl;
}
return 0;
}
1045 快速排序
#include
#include
#include
#include
using namespace std;
int main(void){
int n,cnt=0;
cin>>n;
vector<int> a(n),b(n),v(n);
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];
}
int m=0;
sort(a.begin(),a.end());
for(int i=0;i<n;i++){
if(a[i]==b[i]&&b[i]>m){
v[cnt++]=b[i];
}
if(b[i]>m)
m=b[i];
}
printf("%d\n",cnt);
for(int i=0;i<cnt;i++){
if(i!=0) printf(" ");
cout<<v[i];
}
printf("\n");
return 0;
}
1046 划拳
#include
using namespace std;
int main(void){
int n;
cin>>n;
int a[4];
int m1=0,m2=0;
while(n--){
cin>>a[0]>>a[1]>>a[2]>>a[3];
int n=a[0]+a[2];
if(n==a[1]&&n!=a[3]) m2++;
if(n==a[3]&&n!=a[1]) m1++;
}
printf("%d %d",m1,m2);
return 0;
}
1047 编程团体赛
#include
using namespace std;
int main(void){
int n;
cin>>n;
int team[1001]={0},score,num,t,m;
for(int i=0;i<n;i++){
scanf("%d-%d %d",&t,&num,&score);
team[t]+=score;
}
for(int i=0;i<1001;i++){
if(team[i]>team[m]){
m=i;
}
}
printf("%d %d",m,team[m]);
return 0;
}
1048 数字加密
#include
#include
#include
using namespace std;
int main(void){
string a,b,c;
cin>>a>>b;
reverse(a.begin(),a.end());reverse(b.begin(),b.end());
if(a.size()>b.size())
b.append(a.size()-b.size(),'0');
if(a.size()<b.size())
a.append(b.size()-a.size(),'0');
char str[14] = {"0123456789JQK"};
for(int i=0;i<a.size();i++){
if(i%2==0){
c+=str[(a[i]-'0'+b[i]-'0')%13];
}
else{
int m=b[i]-a[i];
if(m<0) m+=10;
c+=str[m];
}
}
for(int i=c.size()-1;i>=0;i--)
cout<<c[i];
return 0;
}
1049 数列的片段和
#include
#include
using namespace std;
int main(void){
int n;
cin>>n;
double sum=0.0,temp;
for(int i=1;i<=n;i++){
cin>>temp;
sum+=temp*i*(n-i+1);
}
printf("%.2f",sum);
return 0;
}
1050 螺旋矩阵
#include
#include
#include
#include
#include
using namespace std;
bool cmp(int a,int b){return a>b;}
int main(void){
int N;
cin>>N;
int m,n,t=0; \
for (n = sqrt((double)N); n >= 1; n--) {
if (N % n == 0) {
m = N / n;
break;
}
}
vector<int> a(N);
for(int i=0;i<N;i++)
scanf("%d",&a[i]);
sort(a.begin(),a.end(),cmp);
vector<vector<int> > b(m,vector<int>(n));
for(int i=0;i<m/2+m%2;i++){
for (int j = i; j <= n - 1 - i && t <= N - 1; j++)
b[i][j] = a[t++];
for (int j = i + 1; j <= m - 2 - i && t <= N - 1; j++)
b[j][n - 1 - i] = a[t++];
for (int j = n - i - 1; j >= i && t <= N - 1; j--)
b[m - 1 - i][j] = a[t++];
for (int j = m - 2 - i; j >= i + 1 && t <= N - 1; j--)
b[j][i] = a[t++];
}
for (int i = 0; i < m; i++) {
for (int j = 0 ; j < n; j++) {
printf("%d", b[i][j]);
if (j != n - 1) printf(" ");
}
printf("\n");
}
return 0;
}