标签:++ 当当 \n space strlen return 没有 i++ getch
//1
#include<bits/stdc++.h>
using namespace std;
struct node{
string s;
int a,b;
};
int main(){
int n;
scanf("%d",&n);
vector<node>v(n);
for(int i=0;i<n;i++){
cin>>v[i].s>>v[i].a>>v[i].b;
}
int m,t;
scanf("%d",&m);
while(m--){
scanf("%d",&t);
for(int i=0;i<n;i++){
if(v[i].a==t)
cout<<v[i].s<<" "<<v[i].b<<endl;
}
}
return 0;
}
//2
#include<stdio.h>
int main(){
char c;
int a[27]={0};
while((c=getchar())!=‘\n‘){
if(c>=‘A‘&&c<=‘Z‘){
a[c+32-‘a‘+1]++;
}else if(c>=‘a‘&&c<=‘z‘){
a[c-‘a‘+1]++;
}else{
continue;
}
}
int f=1;
for(int i=2;i<27;i++){
if(a[i]>a[f])
f=i;
}
printf("%c %d",f+‘a‘-1,a[f]);
return 0;
}
//3
#include<bits/stdc++.h>
using namespace std;
int main(){
//char a[10000];
string a;
getline(cin,a);
int l=a.length();
int cnt_P,cnt_A,cnt_T,cnt_e,cnt_s,cnt_t;
cnt_P=cnt_A=cnt_T=cnt_e=cnt_s=cnt_t=0;
for(int i=0;i<l;i++){
if(a[i]==‘P‘) cnt_P++;
else if(a[i]==‘A‘) cnt_A++;
else if(a[i]==‘T‘) cnt_T++;
else if(a[i]==‘e‘) cnt_e++;
else if(a[i]==‘s‘) cnt_s++;
else if(a[i]==‘t‘) cnt_t++;
else continue;
}
while(1){
if(cnt_P>0) {cout<<"P";cnt_P--;}
if(cnt_A>0) {cout<<"A";cnt_A--;}
if(cnt_T>0) {cout<<"T";cnt_T--;}
if(cnt_e>0) {cout<<"e";cnt_e--;}
if(cnt_s>0) {cout<<"s";cnt_s--;}
if(cnt_t>0) {cout<<"t";cnt_t--;}
if(cnt_P==0&&cnt_A==0&&cnt_T==0&&cnt_e==0&&cnt_s==0&&cnt_t==0)
break;
}
return 0;
}
//4
///c++的头文件不能用gets(),换行必须单独拿出来放在最后,不能分开
#include<stdio.h>
#include<string.h>
char low[14][5]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char high[14][5]={"#","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main(){
char a[8];
int n;
scanf("%d",&n);
getchar();
while(n--){
gets(a);
if(isdigit(a[0])){
int sum=0;
int l=strlen(a);
for(int i=0;i<l;i++){
sum=sum*10+a[i]-‘0‘;
}
if(sum>12){
printf("%s",high[sum/13]);
if(sum%13) printf(" %s",low[sum%13]);
}else{
printf("%s",low[sum]);
}
}else{
int t=0;
for(int i=0;i<13;i++){
if(strstr(a,low[i])){
t+=i;
break;
}
}
for(int i=1;i<13;i++){
if(strstr(a,high[i])){
t+=i*13;
break;
}
}
printf("%d",t);
}
printf("\n");
}
return 0;
}
//5
//对原序列sort排序,逐个比较,当当前元素没有变化
//并且它左边的所有值的最大值都比它小的时候就可以认为
//它一定是主元
///还有就是直接编会显示超时。。
#include<bits/stdc++.h>
using namespace std;
int v[100000];
int main(){
int n;
scanf("%d",&n);
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];
}
sort(a.begin(),a.end());
int max=0,t=0;
for(int i=0;i<n;i++){
if(a[i]==b[i]&&b[i]>max)
v[t++]=b[i];
if(b[i]>max)
max=b[i];
}
printf("%d\n",t);
for(int i=0;i<t;i++){
if(i!=0) printf(" ");
printf("%d",v[i]);
}
printf("\n");
return 0;
}
标签:++ 当当 \n space strlen return 没有 i++ getch
原文地址:https://www.cnblogs.com/suying/p/10413184.html