1001
#include <stdio.h>
int main(){
int n,count;
count=0;
scanf("%d",&n);
while(n!=1){
if(n%2==0){
n=n/2;
}
else
{
n=(3*n+1)/2;
}
count++;
}
printf("%d",count);
return 0;
}
1002
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//把一个字符串转化为整型 str[n]-'0'
int main()
{
string str,summ;
string str1[10]= {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int m,n,sum;
sum=0;
cin>>str;
m=str.length();
vector <string >ve;
for(n=0; n<m; n++)
{
sum+=str[n]-'0';
}
summ=to_string(sum);
m=summ.length();
for(n=0; n<m; n++)
{
str=str1[summ[n]-'0'];
ve.push_back(str);
}
for(int i=0; i<ve.size(); i++)
{
if(i!=0)
cout<<" ";
cout<<ve[i];
}
}
1003
#include <iostream>
#include <string>
#include <map>
//如何将每个字符串是否符合分别保存
using namespace std;
int main(){
int n,pos1,pos2;
cin>>n;
string str[10];
for(int m=0;m<n;m++)
{
cin>>str[m];
}
map<char,int> mp;
for(int m=0;m<n;m++){
mp['P']=mp['A']=mp['T']=pos1=pos2=0;
for(int k=0;k<str[m].length();k++){
if(str[m][k]=='P')
{
mp['P']+=1;
pos1=k;
}
if(str[m][k]=='T')
{
mp['T']+=1;
pos2=k;
}
if(str[m][k]=='A')
{
mp['A']+=1;
}
}
if((mp['A']+mp['T']+mp['P']==str[m].length())&&pos1*(pos2-pos1-1)==(str[m].length()-pos2-1)&&mp['A']&&mp['P']&&mp['T'])
cout<<"YES"<<endl;//还是需要保证PAT都不为零
else
cout<<"NO"<<endl;
}
return 0;
}
1004
#include <iostream>
#include <algorithm>
using namespace std;
struct student{
string name;
string id;
int grade;
}stdu[10000];
bool cmp(student a,student b)
{
return a.grade>b.grade;
}
int main(){
int n;
cin>>n;
for(int m=0;m<n;m++)
{
cin>>stdu[m].name;
cin>>stdu[m].id;
cin>>stdu[m].grade;
}
sort(stdu,stdu+n,cmp);
cout<<stdu[0].name<<" "<<stdu[0].id<<endl;
cout<<stdu[n-1].name<<" "<<stdu[n-1].id<<endl;
return 0;
}
1005
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
bool cmp(int a,int b)
{
return a>b;
}
using namespace std;
int main(){
int k,m,a[100],b[100];//需要两份
map <int,int> mp;
vector<int> ve;
cin>>k;//使用过的标识符为0 如何保存值与标识位
for(int n=0;n<k;n++)
{
cin>>a[n];
}
for(int n=0;n<k;n++)
{
b[n]=a[n];
}
for(int n=0;n<k;n++)
{
while(a[n]!=1)
{
if(a[n]%2==0)
{
a[n]=a[n]/2;
m=a[n];
mp[m]=1;
}
else
{
a[n]=(3*a[n]+1)/2;
m=a[n];
mp[m]=1;
}
}
}
sort(b,b+k,cmp);
for(int n=0;n<k;n++)
{
if(mp[b[n]]!=1)
ve.push_back(b[n]);
}
for(int i=0;i<ve.size();i++)
{
if(i==0)
cout<<ve[i];
else
cout<<" "<<ve[i];
}
return 0;
}
1006
#include <iostream>
using namespace std;
int main()
{
int n,b,g,s;
cin>>n;
b=n/100;
g=(n-b*100)/10;
s=n%10;
for(int m=0;m<b;m++)
cout<<'B';
for(int m=0;m<g;m++)
cout<<'S';
for(int m=0;m<s;m++)
cout<<m+1;
}
1007
#include <iostream>
#include <vector>
using namespace std;//写一个素数表
bool isPrime(int number)
{
for(int i=2;i*i<=number;i++)
if (number%i==0)
return false;
return true;
}
int main()
{
int n,sum;
sum=0;
cin>>n;
vector <int> ve;
for(int m=2;m<=n;m++)
{
if(isPrime(m)==true)
{
ve.push_back(m);
}
}
for(int i=0;i<ve.size()-1;i++)
{
if(ve[i+1]-ve[i]==2)
sum++;
}
cout<<sum;
}
1008
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,m,k,b[100];
cin>>n;
cin>>m;
vector<int> ve;
for(int i=0;i<n;i++)
{
cin>>k;
ve.push_back(k);
}
for(int i=0;i<n;i++)
{
b[(i+m)%n]=ve[i];
}
for(int i=0;i<n;i++)
{
if(i!=n-1)
cout<<b[i]<<" ";
else
cout<<b[i];
}
}
1009
#include <iostream>
#include <stack>
using namespace std;
int main(){
string str;
stack<string> st;
while(cin>>str)//获得输入以及停止输入
{
st.push(str);
}
cout<<st.top();
st.pop();
while(!st.empty())
{
cout<<" "<<st.top();
st.pop();
}
}
1010
#include <cstdio>
int main(){
int a,b;
int flag = 0;
while(scanf("%d %d",&a,&b)!=EOF){
if(b!=0){
if(flag == 0)printf("%d",a*b);
else printf(" %d",a*b);
printf(" %d",b-1);
flag = 1;
}
}
if(flag==0)printf("0 0");
return 0;
}
1011
#include <iostream>
using namespace std;
bool cmp(long a,long b,long c)
{
if(a+b>c)
return true;
return false;
}
int main()
{
int n,m[10];
cin>>n;
long a,b,c;
for(int i=0; i<n; i++)
{
cin>>a>>b>>c;
m[i]=cmp(a,b,c);
}
for(int i=0; i<n; i++)
{
cout<<"Case #"<<i+1<<": ";
if(m[i]==1)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
}
}
1012
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip> //要用到格式控制符 输出一位小数cout<<" "<<fixed<<setprecision(1)<<A4;
using namespace std;
int main()
{
int n,m,A1=0,A2=0,A3=0,A5=0,sum1=0,sum3=0;
double sum2=0.0,A4=0.0;
cin>>n;
vector<int> ve;
for(int i=0;i<n;i++)
{
cin>>m;
ve.push_back(m);
}
for(int i=0;i<n;i++)
{
if(ve[i]%10==0)
A1+=ve[i];
if(ve[i]%5==1)
{
sum1+=1;
A2+=ve[i]*pow(-1,sum1+1);
}
if(ve[i]%5==2)
A3+=1;
if(ve[i]%5==3)
{
sum2+=1;
sum3+=ve[i];
A4=sum3/sum2;
}
if(ve[i]%5==4)
{
if(ve[i]>A5)
A5=ve[i];
}
}
if(A1>0)
cout<<A1;
else
cout<<"N";
if(sum1>0)
cout<<" "<<A2;
else
cout<<" N";
if(A3>0)
cout<<" "<<A3;
else
cout<<" N";
if(A4>0)
cout<<" "<<fixed<<setprecision(1)<<A4;
else
cout<<" N";
if(A5>0)
cout<<" "<<A5;
else
cout<<" N";
}
1013
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int number)
{
for(int i=2; i*i<=number; i++)
if (number%i==0)
return false;
return true;
}
int main()
{
int m,n,count=0,sum=0;
cin>>m>>n;
vector<int> ve;
for(int i=2; i<1000000; i++)
{
if(isPrime(i)==true)
{
count+=1;
ve.push_back(i);
}
if(count==10000)
break;
}
for(int i=m; i<n+1; i++) //格式的问题如何进行换行,很巧妙
{
sum+=1;
if(sum%10==1)
cout<<ve[i-1];
else
cout<<" "<<ve[i-1];
if(sum%10==0)
cout<<"\n";
}
}
1014
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
string str1,str2,str3,str4;
char a[2];
int count=0,pos;
cin>>str1;
cin>>str2;
cin>>str3;
cin>>str4;
int m;
for(int i=0; i<60; i++)
{
if(str1[i]==str2[i]&&(str1[i]>='A'&&str1[i]<='G'))//注意范围
{
a[0]=str1[i];
pos=i;
break;
}
}
for(int i=pos+1; i<60; i++)
{
if(str1[i]==str2[i]&&((str1[i]>='0'&&str1[i]<='9')||(str1[i]>='A'&&str1[i]<='N')))
{
a[1]=str1[i];
break;
}
}
for(int i=0; i<60; i++)
{
if(str3[i]==str4[i]&&((str3[i]>='A'&&str3[i]<='Z')||(str3[i]>='a'&&str3[i]<='z')))
{
pos=i;
break;
}
}
string days[7]= {"MON","TUE","WED","THU","FRI","SAT","SUN"};
cout<<days[a[0]-'A']<<" ";
if(a[1]>='0'&&a[1]<='9')
m=a[1]-'0';
else
m=a[1]-'A'+10;
printf("%02d:%02d",m,pos);
}
1015
#include <iostream>
#include <stdio.h>
#include <vector>
#include<algorithm>//调用sort
using namespace std;
struct student
{
int id;
int de;
int cai;
};
bool cmp(student a,student b)
{
if((a.de+a.cai)==(b.de+b.cai))
{
if(a.de==b.de)
{
return a.id<b.id;
}
return a.de>b.de;
}
else
return (a.de+a.cai)>(b.de+b.cai);
}
int main()
{
int n,l,h;
scanf("%d%d%d",&n,&l,&h);
student temp;
int total=n;
int sum1=0,sum2=0,sum3=0,sum4=0;
vector <student> ve[4];
for(int i=0; i<n; i++)
{
scanf("%d%d%d",&temp.id,&temp.de,&temp.cai);
if(temp.de<l||temp.cai<l)
total--;
else if(temp.de>=h&&temp.cai>=h)
{
ve[0].push_back(temp);
}
else if(temp.de>=h&&temp.cai<h)
{
ve[1].push_back(temp);
}
else if(temp.de<h&&temp.cai<h&&(temp.de>=temp.cai))
{
ve[2].push_back(temp);
}
else
{
ve[3].push_back(temp);
}
}
printf("%d\n",total);
for(int j=0; j<4; j++)
{
sort(ve[j].begin(),ve[j].end(),cmp);
for(int i=0; i<ve[j].size(); i++)
{
printf("%d %d %d\n",ve[j][i].id,ve[j][i].de,ve[j][i].cai);
}
}
}
1016
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string A,B;
int Da,Db,m,n;
cin>>A>>Da>>B>>Db;
int sum1=0,sum2=0;
int pa=0,pb=0;
for(int i=0; i<A.length(); i++) //(A[i]==Da+30),(A[i]==Da)都不对,搞错了ASCii值是48
{
if(A[i]-'0'==Da)
sum1++;
}
for(int i=0; i<B.length(); i++)
{
if(B[i]-'0'==Db)
sum2++;
}
for(int i=0;i<sum1;i++)
pa=10*pa+Da;
for(int i=0;i<sum2;i++)
pb=10*pb+Db;
cout<<pa+pb;
}
1017
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string a;
vector<int> ve;
int b,c=0,d=0;
cin>>a>>b;
for(int i=0; i<a.length(); i++)
{
c=(a[i]-'0'+10*d)/b;
ve.push_back(c);
d=(a[i]-'0'+10*d)%b;
}
if(ve[0]!=0&&ve.size()>1)
cout<<ve[0];
if(ve[0]==0&&ve.size()==1)
cout<<0;
for(int i=1; i<ve.size(); i++)
cout<<ve[i];
cout<<" "<<d;
}
1018
#include <iostream>
#include <map>//用map代表对应获胜次数
#include <vector>
#include <stdio.h>
using namespace std;
int main()
{
int n;
char a,b,c;//用来获得输入
int j,k;
char x,y;//用来确定哪个字符最小
cin>>n;
map<char,int> mp1;
map<char,int> mp2;
getchar();
for(int i=0; i<n; i++)
{
cin>>a>>b;
if(a=='C'&&b=='B')
mp2['B']+=1;
if(a=='C'&&b=='J')
mp1['C']+=1;
if(a=='B'&&b=='C')
mp1['B']+=1;
if(a=='B'&&b=='J')
mp2['J']+=1;
if(a=='J'&&b=='B')
mp1['J']+=1;
if(a=='J'&&b=='C')
mp2['C']+=1;
}
if(mp1['J']>mp1['B'])
{
if(mp1['J']>mp1['C'])
x='J';
else
x='C';
}
else
{
if(mp1['B']>=mp1['C'])
x='B';
else if(mp1['C']>mp1['B'])
x='C';
}
if(mp2['J']>mp2['B'])
{
if(mp2['J']>mp2['C'])
y='J';
else
y='C';
}
else
{
if(mp2['B']>=mp2['C'])
y='B';
else
y='J';
}
j=mp1['J']+mp1['C']+mp1['B'];
k=mp2['J']+mp2['C']+mp2['B'];
cout<<j<<" "<<n-j-k<<" "<<k<<endl;
cout<<k<<" "<<n-j-k<<" "<<j<<endl;
cout<<x<<" "<<y;
}
1019
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
bool cmp(int a,int b)
{
if(a>b)
return true;
else
return false;
}
int main()
{
int n,q,b,s,g,z,y;
cin>>n;
int a[4];
vector <int> ve1;
for(int i=0; i<1000; i++)
{
q=n/1000;
b=n/100-10*q;
s=n/10-100*q-10*b;
g=n%10;
ve1.push_back(q);
ve1.push_back(b);
ve1.push_back(s);
ve1.push_back(g);
if(q==b&&s==g&&b==s)
{
printf("%04d - %04d = %04d\n",n,n,n-n);
break;
}
sort(ve1.begin(),ve1.end(),cmp);
z=ve1[0]*1000+ve1[1]*100+ve1[2]*10+ve1[3];
y=ve1[3]*1000+ve1[2]*100+ve1[1]*10+ve1[0];
n=z-y;
printf("%04d - %04d = %04d\n",z,y,n);
if(n==6174)
break;
ve1.clear();
}
}
1020
#include <iostream>//看了一下思路,是一个比较巧妙的想法,计算每个的单价
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
struct mc
{
double store;
double price;
double uniprice;
} var[1000];
bool cmp(mc a,mc b)
{
if(a.uniprice>b.uniprice)//小于是从大到小,大于是从小到大
return true;
else
return false;
}
int main()
{
int n,d;
double sum1=0,sum2=0,sum3=0;//一个是价格总,一个是货物总,一个是保留上次的货物量
vector <mc> ve;
cin>>n>>d;
for(int i=0; i<n; i++)
cin>>var[i].store;
for(int i=0; i<n; i++)
cin>>var[i].price;
for(int i=0; i<n; i++)
{
var[i].uniprice=var[i].price/var[i].store;
ve.push_back(var[i]);
}
sort(ve.begin(),ve.end(),cmp);
for(int i=0; i<ve.size(); i++)
{
sum2+=ve[i].store;
if(sum2<d)
sum1+=ve[i].store*ve[i].uniprice;
else
{
sum1+=(d-sum3)*ve[i].uniprice;
break;
}
sum3=sum2;
}
cout<<fixed<<setprecision(2)<<sum1<<endl;
}
1021
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
string str;
cin>>str;
map<int,int> mp;
for(int i=0;i<str.length();i++)
{
for(int m=0;m<10;m++)
{
if(str[i]==m+'0')
mp[m]+=1;
}
}
for(int i=0;i<10;i++)
{
if(mp[i]!=0)
cout<<i<<":"<<mp[i]<<endl;
}
}
1022
#include <iostream>
using namespace std;
int main()
{
int a,b,d,y,num=0;
int z[31];
cin>>a>>b>>d;
y=a+b;
do{
z[num++]=y%d;
y=y/d;
}while(y!=0);
for(int i=num-1;i>=0;i--)
cout<<z[i];
}
1023
#include <iostream>
#include <map>
using namespace std;
int main()
{
int sum1,pos;
map<int,int> mp;
for(int i=0; i<10; i++)
cin>>mp[i];
for(int i=1; i<10; i++)
{
pos=i;
if(mp[i]>=1)
break;
}
if(mp[0]>0)
cout<<pos;
for(int i=0; i<10; i++)
{
sum1=0;
if(i==pos&&mp[0]>0)
sum1=1;
while(sum1<mp[i])
{
cout<<i;
sum1++;
}
}
}
1024
#include <iostream>
#include <map>
#include <math.h>
using namespace std;
int main()
{
string inte1,inte2,inte3;
string a,b;
string str1;
cin>>str1;
int pos=str1.find('E');
int n=str1.length();
//a决定第一个是否输出符号,inte3决定是0.还是向右移动
a=str1.substr(0,1);
inte1=str1.substr(1,1);
inte2=str1.substr(3,pos-3);
inte3=str1.substr(pos+2,n-2-pos);
b=str1.substr(pos+1,1);
string str=inte2;
int c=stoi(inte3);
if(a=="-")
cout<<a;
if(b=="-")
{
cout<<"0.";
for(int i=1; i<c; i++)
cout<<"0";
cout<<inte1<<inte2;
}
else
{
//如果在inte2的位数小于inte3的情况下,正常输出补0就好
//如果位数大于inte3,那么还要加入小数点再进行输出
if(str.length()<=c)
{
cout<<inte1<<inte2;
for(int i=str.length(); i<c; i++)
cout<<"0";
}
else
{
cout<<inte1;
for(int i=0; i<c; i++)
cout<<str[i];
cout<<".";
for(int i=c; i<str.length(); i++)
cout<<str[i];
}
}
}
1025
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,k,sum=0;
int beginad;
cin>>beginad>>n>>k;
int address;
int data[100000];
int next[100000];
int a[100000];
for(int i=0; i<n; i++)
{
cin>>address;
cin>>data[address]>>next[address];
}
for(int i=0; i<n; i++)
{
if(beginad!=-1)
{
a[sum++]=beginad;
beginad=next[beginad];
}
}
for(int i=0; i<sum-sum%k; i+=k)
{
reverse(begin(a)+i,begin(a)+i+k);
}
for(int i=0; i<sum; i++)
{
if(i!=sum-1)
printf("%05d %d %05d\n",a[i],data[a[i]],a[i+1]);
else
printf("%05d %d %d\n",a[i],data[a[i]],-1);
}
}
1026
#include <iostream>
#include <time.h>
#include<math.h>
using namespace std;
int main()
{
double c1,c2,n;
int a,b,c;
cin>>c1>>c2;
n=round((c2-c1)/100);
a=n/3600;
b=n/60-a*60;
c=n-3600*a-60*b;
printf("%02d:%02d:%02d",a,b,c);
}
1027
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,a=1,sum=1,m,x,y,b,c;//x是星号数,y是空格数
vector<int> ve;
char k,f;
scanf("%d%c%c",&n,&k,&f);//7
for(int i=1;;i++)
{
ve.push_back(a);
a+=2;//下一层要添加的
if(sum+2*a>n)
break;
sum+=2*a;//新增以后的总个数
}
m=ve.size();//m是一半的层数
for(int i=0;i<2*m-1;i++)//i是行数
{
x=abs(m-1-i);
y=m-1-abs(m-1-i);
for(int b=0;b<y;b++)
{
cout<<" ";
}
for(int c=0;c<ve[x];c++)
{
cout<<f;
}
cout<<"\n";
}
cout<<n-sum;
}
1028
#include <iostream>
#include <vector>//结构体插入 通过if检测是否年月日都满足条件
#include <algorithm>
using namespace std;
int main()
{
int n,sum=0;
string name,date;
string maxdate="1814/09/06",mindate="2014/09/06";
string maxname,minname;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>name>>date;
if(date>="1814/09/06"&&date<="2014/09/06")
{
sum++;
if(date>=maxdate)
{
maxdate=date;
maxname=name;
}
if(date<=mindate)
{
mindate=date;
minname=name;
}
}
}
cout<<sum;
if(sum!=0)
cout<<" "<<minname<<" "<<maxname;
}
1029
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
string str1,str2,ans;
int pos1=0,pos2=0;
cin>>str1>>str2;
transform(str1.begin(),str1.end(),str1.begin(),::toupper);
transform(str2.begin(),str2.end(),str2.begin(),::toupper);
for(int i=0;i<str1.length();i++)
{
if((str2.find(str1[i])==str2.npos)&&(ans.find(str1[i])==ans.npos))
ans+=str1[i];
}
cout<<ans;
}
1030
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long long n,p,m,ans=0;
cin>>n>>p;
vector <int> ve;
for(int i=0; i<n; i++)
{
cin>>m;
ve.push_back(m);
}
sort(ve.begin(),ve.end());
for(int i=0; i<n; i++)
{
for(int k=i+ans; k<n; k++)
{
if(ve[i]*p>=ve[k])
{
if(k-i+1>=ans)
ans=k-i+1;
}
else
break;
}
}
cout<<ans;
}
1031
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,length,sum=0;//k是计算有效个数
cin>>n;
int b[17]= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
vector<string>ve;
string str;
int a[11]= {'1','0','X','9','8','7','6','5','4','3','2'};
for(int i=0; i<n; i++)
{
length=0;
cin>>str;
for(int i=0; i<17; i++)
{
if(str[i]>='0'&&str[i]<='9')
length++;
}
if(length==17)
{
sum=0;
for(int i=0; i<17; i++)
sum+=(str[i]-'0')*b[i];
sum%=11;
if(a[sum]!=str[17])
ve.push_back(str);
}
else
ve.push_back(str);
}
if(ve.size()==0)
cout<<"All passed";
else
{
for(int i=0; i<ve.size(); i++)
cout<<ve[i]<<endl;
}
}
1032
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n,id,grade,maxgrade=0,maxid=0;
cin>>n;
map<int,int> mp;
for(int i=0; i<n; i++)
{
cin>>id>>grade;
mp[id]+=grade;
}
for(int i=0; i<mp.size(); i++)
{
if(mp[i]>maxgrade)
{
maxgrade=mp[i];
maxid=i;
}
}
cout<<maxid<<" "<<maxgrade;
}
1033
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
string bad,should;
getline(cin,bad);
getline(cin,should);
for(int i=0;i<should.length();i++)
{
if(bad.find(toupper(should[i]))!=bad.npos)
continue;
if(isupper(should[i])&&bad.find('+')!=bad.npos)
continue;
cout<<should[i];
}
}
1034
#include <iostream>
#include <cmath>
using namespace std;
long long a, b, c, d;
long long gcd(long long t1, long long t2) {
return t2 == 0 ? t1 : gcd(t2, t1 % t2);
}
void func(long long m, long long n) {
if (m * n == 0) {
printf("%s", n == 0 ? "Inf" : "0");
return ;
}
bool flag = ((m < 0 && n > 0) || (m > 0 && n < 0));
m = abs(m); n = abs(n);
long long x = m / n;
printf("%s", flag ? "(-" : "");
if (x != 0) printf("%lld", x);
if (m % n == 0) {
if(flag) printf(")");
return ;
}
if (x != 0) printf(" ");
m = m - x * n;
long long t = gcd(m, n);
m = m / t; n = n / t;
printf("%lld/%lld%s", m, n, flag ? ")" : "");
}
int main() {
scanf("%lld/%lld %lld/%lld", &a, &b, &c, &d);
func(a, b); printf(" + "); func(c, d); printf(" = "); func(a * d + b * c, b * d); printf("\n");
func(a, b); printf(" - "); func(c, d); printf(" = "); func(a * d - b * c, b * d); printf("\n");
func(a, b); printf(" * "); func(c, d); printf(" = "); func(a * c, b * d); printf("\n");
func(a, b); printf(" / "); func(c, d); printf(" = "); func(a * d, b * c);
return 0;
}
1035
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int n,pos,h,k;
cin>>n;
vector<int>v1;
vector<int>v2;
vector<int>v3;
for(int i=0;i<n;i++)
{
cin>>h;
v1.push_back(h);
}
for(int i=0;i<n;i++)
{
cin>>h;
v2.push_back(h);
}
for(int i=0;i<n;i++)
{
if(v2[i]>v2[i+1])
{
pos=i+1;
k=pos;
break;
}
}
while(v1[pos]==v2[pos]&&pos<n)
pos++;
if(pos==n)
{
cout<<"Insertion Sort"<<endl;
sort(v1.begin(),v1.begin()+k+1);
}
else
{
cout<<"Merge Sort"<<endl;
int flag=1,k=1;
while(flag)
{
flag=0;
for(int i=0;i<n;i++)
{
if(v1[i]!=v2[i])
flag=1;
}
k=k*2;
for(int i=0;i<n/k;i++)
sort(v1.begin()+i*k,v1.begin()+(i+1)*k);
sort(v1.begin()+n/k*k,v1.end());
}
}
for(int i=0;i<v1.size();i++)
{
if(i!=0)
cout<<" ";
cout<<v1[i];
}
}
1036
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n,a,c;
scanf("%d%c%c",&n,&a,&c);
for(int i=0;i<n;i++)
{
printf("%c",c);
}
printf("\n");
for(int m=0;m<round(n/2.0)-2;m++)
{
for(int i=0;i<n;i++)
{
if(i==0||i==n-1)
printf("%c",c);
else
printf(" ");
}
printf("\n");
}
for(int i=0;i<n;i++)
{
printf("%c",c);
}
}
1037
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int Galleon1,Sickle1,Knut1;
int Galleon2,Sickle2,Knut2;
int n1,n2;//西可个数
char a,b,c,d;
int Galleon3,Sickle3,Knut3;//被找的个数
cin>>Galleon1>>a>>Sickle1>>b>>Knut1>>Galleon2>>c>>Sickle2>>d>>Knut2;
n1=Galleon1*17*29+Sickle1*29+Knut1;
n2=Galleon2*17*29+Sickle2*29+Knut2;
Galleon3=(n2-n1)/(17*29);
Sickle3=(n2-n1)/29-Galleon3*17;
Knut3=(n2-n1)%29;
cout<<Galleon3<<"."<<abs(Sickle3)<<"."<<abs(Knut3);
}
1038
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,k,m,num;
cin>>n;
vector <int> ve1(1000);
vector <int> ve2;
for(int i=0; i<n; i++)
{
cin>>m;
ve1[m]++;
}
cin>>k;
for(int i=0; i<k; i++)
{
cin>>m;
ve2.push_back(ve1[m]);
}
cout<<ve2[0];
for(int i=1; i<ve2.size(); i++)
cout<<" "<<ve2[i];
}
1039
#include <iostream>
using namespace std;
int main()
{
string str1,str2;
int n,m,sum=0;
getline(cin,str1);
getline(cin,str2);
for(int i=0;i<str2.length();i++)
{
n=str1.length();
if(str1.find(str2[i])!=str1.npos)
{
m=str1.find(str2[i]);
str1=str1.substr(0,m)+str1.substr(m+1,n-m-1);
}
else
sum++;
}
if(sum>0)
cout<<"No "<<sum;
else
cout<<"Yes "<<str1.length();
}
1040
#include <iostream>
using namespace std;
int main()
{
string str;
getline(cin,str);
int sumT=0,sumP=0;
long long sum=0;
for(int i=0;i<str.length();i++)
{
if(str[i]=='T')
sumT++;
}
for(int i=0;i<str.length();i++)
{
if(str[i]!='A')
{
if(str[i]=='P')
sumP++;
else
sumT--;
}
else
sum+=sumP*sumT;
}
cout<<sum%1000000007;
}
1041
#include <iostream>
#include <string>
#include <vector>
using namespace std;//必须在声明字符串前使用
struct student
{
string id;
int tryseat;
int examseat;
}st[1000];
int main()
{
int n,m,x;
vector<int> ve;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>st[i].id>>st[i].tryseat>>st[i].examseat;
}
cin>>m;
for(int i=0;i<m;i++)
{
cin>>x;
ve.push_back(x);
}
for(int k=0;k<ve.size();k++)
{
for(int i=0;i<n;i++)
{
if(ve[k]==st[i].tryseat)
cout<<st[i].id<<" "<<st[i].examseat<<endl;
}
}
}
1042
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string st;
getline(cin,st);
int maxi=0;
int a[26]={0};
transform(st.begin(),st.end(),st.begin(),::tolower);
for(int i=0;i<st.size();i++)
{
if(islower(st[i]))
a[st[i]-'a']++;
}
for(int i=0;i<26;i++)
{
if(a[i]>a[maxi])
maxi=i;
}
printf("%c %d",'a'+maxi,a[maxi]);
}
1043
#include <iostream>
#include <map>
using namespace std;
int main()
{
string str;
cin>>str;
map<char,int> mp;
for(int i=0; i<str.length(); i++)
{
mp[str[i]]++;
}
while((mp['P']>0)||(mp['A']>0)||(mp['T']>0)||(mp['e']>0)||(mp['s']>0)||(mp['t']>0))
{
if(mp['P']-->0)
cout<<'P';
if(mp['A']-->0)
cout<<'A';
if(mp['T']-->0)
cout<<'T';
if(mp['e']-->0)
cout<<'e';
if(mp['s']-->0)
cout<<'s';
if(mp['t']-->0)
cout<<'t';
}
}
1044
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,pos1=0,pos2=0;
cin>>n;
getchar();
string st,str1,str2;
vector <string> ve;
string a[13]= {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string b[12]= {"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
for(int i=0; i<n; i++)
{
getline(cin,st);
ve.push_back(st);
}
for(int i=0; i<ve.size(); i++)
{
if(ve[i][0]>='0'&&ve[i][0]<='9')
{
int ot = stoi(ve[i]);
if(ot%13==0&&ot/13!=0)
cout<<b[(ot/13)-1]<<endl;
if(ot%13!=0&&ot/13!=0)
cout<<b[(ot/13)-1]<<" "<<a[ot%13]<<endl;
if(ot/13==0)
cout<<a[ot%13]<<endl;
}
else
{
if(ve[i].length()>=6)
{
str1=ve[i].substr(0,3);
for(int m=0; m<12; m++)
{
if(b[m]==str1)
pos1=m;
}
if(ve[i].length()==7)
str2=ve[i].substr(4,3);
else
str2=ve[i].substr(4,4);
for(int n=0; n<13; n++)
{
if(a[n]==str2)
pos2=n;
}
cout<<(pos1+1)*13+pos2<<endl;
}
else
{
for(int k=0; k<12; k++)
{
if(b[k]==ve[i])
cout<<(k+1)*13<<endl;
}
for(int k=0; k<13; k++)
{
if(a[k]==ve[i])
cout<<k<<endl;
}
}
}
}
}
1045
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> ve1;
vector<int> ve2;
vector<int> ve3;
int n,m,maxi=0,sum=0;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>m;
ve1.push_back(m);
ve2.push_back(m);
}
sort(ve1.begin(),ve1.end());
for(int i=0; i<n; i++)
{
if(ve1[i]==ve2[i]&&ve2[i]>maxi)
{
sum++;
ve3.push_back(ve2[i]);
}
if(ve2[i]>maxi)
maxi=ve2[i];
}
cout<<sum<<endl;
for(int i=0;i<ve3.size();i++)
{
if(i!=0)
cout<<" ";
cout<<ve3[i];
}
cout<<endl;
}
1046
#include <iostream>
using namespace std;
struct hq
{
int js;
int jh;
int ys;
int yh;
}a[100];
int main()
{
//同时输赢不算
int n;
cin>>n;
int pos1,pos2;//甲乙正确次数
int c=0,d=0;//甲乙获胜次数
for(int i=0;i<n;i++)
{
cin>>a[i].js>>a[i].jh>>a[i].ys>>a[i].yh;
}
for(int i=0;i<n;i++)
{
pos1=pos2=0;
if(a[i].jh==(a[i].js+a[i].ys))
pos1=1;
if(a[i].yh==(a[i].js+a[i].ys))
pos2=1;
if(pos1>pos2)
d+=1;
if(pos2>pos1)
c+=1;
}
cout<<c<<" "<<d;
}
1047
#include <iostream>//跟32题几乎一模一样
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,id,memid,grade,maxgrade=0,maxid=0;
char c;
cin>>n;
int a[1000]={0};
for(int i=0; i<n; i++)
{
cin>>id>>c>>memid>>grade;
a[id]+=grade;
}
for(int i=0; i<1000; i++)
{
if(a[i]>a[maxid])
{
maxgrade=a[i];
maxid=i;
}
}
cout<<maxid<<" "<<maxgrade;
}
1048
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
string str1,str2;
cin>>str1>>str2;
char a[13]={'0','1','2','3','4','5','6','7','8','9','J','Q','K'};
int n,m;
int pos1=0,pos2=0;
m=str1.length();
n=str2.length();
int k=max(m,n);
str1=str1.insert(0,k-m,'0');
str2=str2.insert(0,k-n,'0');
reverse(str1.begin(),str1.end());
reverse(str2.begin(),str2.end());
for(int i=0;i<str1.length();i++)
{
if((i+1)%2==1)
{
pos1=(str1[i]+str2[i]-'0'-'0')%13;
str2[i]=a[pos1];
}
else
{
pos2=str2[i]-str1[i];
str2[i]=pos2+'0';
if(pos2<0)
str2[i]=pos2+10+'0';
}
}
for(int i=str2.length()-1;i>=0;i--)
cout<<str2[i];
}
1049
#include <cstdio>
int main(){
int n;
double v,ans = 0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf", &v);
ans+=v*i*(n + 1 - i);
}
printf("%.2f\n",ans);
return 0;
}
1050
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int N,i,m,n,t=0,h;
cin>>N;
string str;
vector<int> v;
vector<int>a(N);
for(int i=0;i<N;i++)
{
cin>>h;
v.push_back(h);
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++)
a[i]=v[i];
n=sqrt(N);
while(N%n!=0)
{
n--;
}
m=N/n;
int level = m / 2 + m % 2;
vector<vector<int>>b(m,vector<int>(n));
for (int i = 0; i < level; 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 k=0;k<n;k++)
{
if(k!=0)
cout<<" ";
cout<<b[i][k];
}
cout<<"\n";
}
}
1051
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
double r1,p1,r2,p2;
scanf("%lf%lf%lf%lf",&r1,&p1,&r2,&p2);
double a,b;
a=r1*r2*(cos(p1)*cos(p2)-sin(p1)*sin(p2));
b=r1*r2*(cos(p2)*sin(p1)+sin(p2)*cos(p1));
if(a<0.005&&a>-0.005)
printf("0.00") ;//介于0的范围内就算四舍五入也是这个值
else
printf("%.2f",a);
if(b>=0.005)
printf("+%.2fi",b);
else if(b<0.005&&b>-0.005)//同上
printf("+0.00i");
else
printf("-%.2fi",-1*b);
}
1052
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string str,str1;
vector<vector<string>> v(3);
int a,b,c,d,e;
for(int i=0; i<3; i++)
{
getline(cin,str);
for(int h=0;h<10; h++)
{
if(str.find('[')==str.npos)
break;
a=str.find('[');
b=str.find(']');//0 2
str1=str.substr(a+1,b-a-1);
v[i].push_back(str1);
str=str.substr(b+1);
}
}
int k;
cin>>k;
for(int i=0;i<k;i++)
{
cin>>a>>b>>c>>d>>e;
if((a<=v[0].size()&&a>0)&&(e<=v[0].size()&&e>0)&&(b<=v[1].size()&&b>0)&&(d<=v[1].size()&&d>0)&&(c<=v[2].size()&&c>0))
cout<<v[0][a-1]<<"("<<v[1][b-1]<<v[2][c-1]<<v[1][d-1]<<")"<<v[0][e-1]<<endl;
else
cout<<"Are you kidding me? @\\/@"<<endl;
}
}
1053
#include <iostream>
using namespace std;
int main()
{
double n,e,d,k,E,sum,sum1=0,sum2=0;
cin>>n>>e>>d;
for(int i=0;i<n;i++)
{
cin>>k;
sum=0;
for(int h=0;h<k;h++)
{
cin>>E;
if(E<e)
sum+=1;
}
if(sum>k/2&&k>d)
sum1+=1;
if(sum>k/2&&k<=d)
sum2+=1;
}
printf("%.1f%% %.1f%%",sum2*100/n,sum1*100/n);
}
1054
错误原因:应该是对比出问题 输出没有问题
学习:这样可以比较前后的字符串是否发生变化
scanf("%s",a);
sscanf(a,"%lf",&c);
sprintf(b,"%.2f",c);
int flag=0;
for(int h=0; h<strlen(a); h++)
{
if(a[h]!=b[h])
flag=1;
}
1055
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct people
{
string name;
int height;
} a[10000];
bool cmp(people a,people b)
{
if(a.height!=b.height)
return a.height>b.height;
if(a.name!=b.name)
return a.name<b.name;
}
int main()
{
int n,k,m;
cin>>n>>k;
vector<people> v;
for(int i=0; i<n; i++)
{
cin>>a[i].name>>a[i].height;
v.push_back(a[i]);
}
sort(v.begin(),v.end(),cmp);
int t = 0, row = k;
while(row)
{
if(row == k)
m = n - n / k * (k - 1);
else
m = n / k;
vector<string> ans(m);
ans[m / 2] = v[t].name;//中间的人 t=0
// 左边一列
int j = m / 2 - 1;
for(int i = t + 1; i < t + m; i = i + 2)//单数
ans[j--] = v[i].name;
// 右边一列
j = m / 2 + 1;
for(int i = t + 2; i < t + m; i = i + 2)//双数
ans[j++] = v[i].name;
// 输出当前排
cout << ans[0];
for(int i = 1; i < m; i++)
cout << " " << ans[i];
cout << endl;
t = t + m;
row--;
}
}
1056
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,m,sum=0;
cin>>n;
vector<int>ve;
for(int i=0;i<n;i++)
{
cin>>m;
ve.push_back(m);
}
for(int i=0;i<n;i++)
{
sum+=ve[i];
}
cout<<sum*(n-1)+sum*10*(n-1);
}
1057
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string str;
int sum=0,sum1=0;
int a=0,b=0;
getline(cin,str);
transform(str.begin(),str.end(),str.begin(),::tolower);
for(int i=0; i<str.length(); i++)
{
if(str[i]>=97&&122>=str[i])
sum+=str[i]-'a'+1;
}
while(sum!=0)
{
sum1=sum%2;
sum=sum/2;
if(sum1==0)
a+=1;
if(sum1==1)
b+=1;
}
cout<<a<<" "<<b<<endl;
}
1058
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n,m,a,b;
string str,str1;
cin>>n>>m;
getline(cin,str);
vector<int> ve;
vector<string> ve1;
vector<string> ve2;
vector<vector<string>> ve3;
vector<int> ve4;
map<int,int>mp;
map<int,int>mp1;
for(int i=0;i<m;i++)
{
getline(cin,str);
ve.push_back(str[0]-'0');
ve1.push_back(str.substr(4));
}
for(int i=0;i<n;i++)
{
getline(cin,str);
ve2.clear();
for(int h=0;; h++)
{
if(str.find('(')==str.npos)
break;
a=str.find('(');
b=str.find(')');//0 2
str1=str.substr(a+1,b-a-1);
str=str.substr(b+1);
ve2.push_back(str1);
}
ve3.push_back(ve2);
}
for(int i=0;i<n;i++)//3
{
for(int h=0;h<m;h++)//4
{
if(ve1[h]==ve3[i][h])
{
mp1[h]++;
mp[i]+=ve[h];
}
}
cout<<mp[i]<<endl;
}
for(int i=0;i<m;i++)
ve4.push_back(mp1[i]);
sort(ve4.begin(),ve4.end());
if(ve4[0]==n)
cout<<"Too simple";
else
{
cout<<n-ve4[0];
for(int i=0;i<m;i++)
{
if(ve4[0]==mp1[i])
cout<<" "<<i+1;
}}
}
1059
#include <iostream>
#include <vector>
using namespace std;
bool isPrime(int number)
{
for(int i=2; i*i<=number; i++)
if (number%i==0)
return false;
return true;
}
void fuc(int m,int a[],int b[])
{
if(a[m]==0)
cout<<": Are you kidding?"<<endl;
else
{
if(b[m]>0)
cout<<": Checked"<<endl;
else
{
b[m]=1;
if(a[m]==1)
cout<<": Mystery Award"<<endl;
else if(isPrime(a[m]))
cout<<": Minion"<<endl;
else
cout<<": Chocolate"<<endl;
}
}
}
int main()
{
int n,m;
cin>>n;
int a[10001]= {0};
int b[10001]= {0};
vector <int> ve;
for(int i=0; i<n; i++)
{
cin>>m;
a[m]=i+1;
}
int k;
cin>>k;
for(int i=0; i<k; i++)
{
cin>>m;
ve.push_back(m);
}
for(int i=0;i<k;i++)
{
printf("%04d",ve[i]);
fuc(ve[i],a,b);
}
}
1060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,m,pos=0;
cin>>n;
vector <int> ve;
for(int i=0; i<n; i++)
{
cin>>m;
ve.push_back(m);
}
sort(ve.begin(),ve.end());
reverse(ve.begin(),ve.end());
for(int i=0; i<n; i++)
{
if(ve[i]>i+1)
{
pos=i+1;
}
}
cout<<pos;
}
1061
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,m,sum;
int x;//正确答案分数/选项
cin>>n>>m;
vector <int> ve1;//正确答案分数
vector <int> ve2;//正确答案选项
vector <int> ve3;//存储分数
for(int i=0; i<m; i++)
{
cin>>x;
ve1.push_back(x);
}
for(int i=0; i<m; i++)
{
cin>>x;
ve2.push_back(x);
}
for(int k=0; k<n; k++)
{
sum=0;
for(int i=0; i<m; i++)
{
cin>>x;
if(x==ve2[i])
sum+=ve1[i];
}
ve3.push_back(sum);
}
for(int i=0;i<ve3.size();i++)
cout<<ve3[i]<<endl;
}
1062
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n1,n2,k,pos,m1,m2;
char a,b;
vector <int> ve;
vector<int>ve1;
cin>>n1>>a>>m1>>n2>>b>>m2>>k;
for(int i=0; i<k; i++)
{
if(((m1*i>n1*k)&&(n2*k>i*m2))||((m1*i<n1*k)&&(n2*k<i*m2)))
ve.push_back(i);
}
for(int i=0;i<ve.size();i++)
{
pos=1;
for(int h=2;h<k;h++)
{
if((ve[i]%h==0)&&(k%h==0))
pos=h;
}
if(pos==1)
ve1.push_back(ve[i]);
}
cout<<ve1[0]<<"/"<<k;
for(int i=1;i<ve1.size();i++)
cout<<" "<<ve1[i]<<"/"<<k;
}
1063
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
bool cmp(double a,double b)
{
if(a>b)
return true;
else
return false;
}
using namespace std;
int main()
{
int n;
cin>>n;
int a,b;
double c,d;
vector <double> ve;
for(int i=0;i<n;i++)
{
cin>>a>>b;
c=pow(a,2)+pow(b,2);
d=pow(c,0.5);
ve.push_back(d);
}
sort(ve.begin(),ve.end(),cmp);
cout<<fixed<<setprecision(2)<<ve[0];
}
1064
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int n,sum;
string str;
cin>>n;
set<int> s;
for(int i=0; i<n; i++)
{
sum=0;
cin>>str;
for(int m=0; m<str.length(); m++)
{
sum+=str[m]-'0';
}
s.insert(sum);
}
cout<<s.size()<<endl;
for(auto it=s.begin ();it!=s.end ();it++)
{
if(it!=s.begin())
cout<<" ";
cout<<*it;
}
}
1065
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main()
{
int n,m;
cin>>n;
int x,y,k;
set<int> s;
int a[100000]= {0};
int b[100000]= {0};
vector<int> ve;
for(int i=0; i<n; i++)
{
cin>>x>>y;
a[x]=y;
a[y]=x;
}
cin>>m;
for(int i=0; i<m; i++)
{
cin>>x;
b[x]=1;
ve.push_back(x);
}
for(int i=0; i<m; i++)
{
k=ve[i];
if(b[a[k]]!=1)
s.insert(k);
}
cout<<s.size()<<endl;
for(auto it = s.begin(); it != s.end(); it++)
{
if(it!=s.begin())
cout<<" ";
printf("%05d",*it);
}
}
1066
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int m,n,a,b,c;
int h;
string str;
vector <int> ve;
vector <vector <int> >ve1;
cin>>m>>n>>a>>b>>c;
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
cin>>h;
if((h>=a)&&(h<=b))
ve.push_back(c);
else
ve.push_back(h);
}
ve1.push_back(ve);
ve.clear();
}
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
if(j!=0)
cout<<" ";
printf("%03d",ve1[i][j]);
}
printf("\n");
}
}
1067
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string str1,str2;
int n,sum=0;
cin>>str1>>n;
getchar();
vector <string> ve;
for(int i=0;; i++)
{
getline(cin,str2);
if(str2!="#")
ve.push_back(str2);
else
break;
}
for(int i=0; i<ve.size(); i++)
{
sum+=1;
if(ve[i]==str1)
{
cout<<"Welcome in";
break;
}
cout<<"Wrong password: "<<ve[i]<<endl;
if(sum==n)
{
cout<<"Account locked";
break;
}
}
}
1068
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int m,n,tol,temp,sum=0;
int a,b;
cin>>m>>n>>tol;
vector<int> v;
vector<vector<int>> ve;
vector<int> ve1;
vector<int> ve2;
set<int>s;
map<int,int> mp;
int k[1000];
for (int i = 0; i <n; i++)//输入r*c的二维数组
{
v.clear();//子数组返回时要清除
for (int j = 0; j <m; j++)
{
cin >> temp;
v.push_back(temp);
s.insert(temp);
}
ve.push_back(v);
}
for(auto it=s.begin(); it!=s.end(); it++)
{
a=*it;
for(int i=0; i<n; i++)
{
b=count(ve[i].begin(),ve[i].end(),a);
mp[a]+=b;
}
}
for(int x=0; x<n; x++)
{
for(int y=0; y<m; y++)
{
sum=0;
if(mp[ve[x][y]]==1)
{
sum+=x>0&&y>0?(fabs(ve[x][y]-ve[x-1][y-1])>tol):1;
sum+=x>0?(fabs(ve[x][y]-ve[x-1][y])>tol):1;
sum+=x>0&&y<m-1?(fabs(ve[x][y]-ve[x-1][y+1])>tol):1;
sum+=y>0?(fabs(ve[x][y]-ve[x][y-1])>tol):1;
sum+=y<m-1?(fabs(ve[x][y]-ve[x][y+1])>tol):1;
sum+=x<n-1&&y>0?(fabs(ve[x][y]-ve[x+1][y-1])>tol):1;
sum+=x<n-1?(fabs(ve[x][y]-ve[x+1][y])>tol):1;
sum+=x<n-1&&y<m-1?(fabs(ve[x][y]-ve[x+1][y+1])>tol):1;
if(sum==8)
{
ve1.push_back(x);
ve1.push_back(y);
}
}
}
}
if(ve1.size()==2)
cout<<"("<<ve1[1]+1<<", "<<ve1[0]+1<<"): "<<ve[ve1[0]][ve1[1]];
if(ve1.size()>2)
cout<<"Not Unique";
if(ve1.size()==0)
cout<<"Not Exist";
}
1069
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
int m,n,s;
cin>>m>>n>>s;
string str;
vector<string> ve;
vector<string> ve2;
set<string>s1 ;
for(int i=0; i<m; i++)
{
cin>>str;
ve.push_back(str);
}
if(s>m)
cout<<"Keep going...";
else
{
for(int i=s-1; i<m; i+=n)
{
if(s1.find(ve[i])==s1.end())
{
cout<<ve[i]<<endl;
s1.insert(ve[i]);
ve2.push_back(ve[i]);
}
else
{
while(s1.find(ve[i])!=s1.end())
i++;
cout<<ve[i]<<endl;
}
}
}
}
1070
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
bool cmp(int a,int b)
{
if(a<b)
return true;
else
return false;
}
using namespace std;
int main()
{
int n,m;
double sum=0;
cin>>n;
vector <int> ve;
for(int i=0; i<n; i++)
{
cin>>m;
ve.push_back(m);
}
sort(ve.begin(),ve.end(),cmp);
sum=ve[0];
for(int i=1; i<n; i++)
sum=(sum+ve[i])/2;
cout<<int(sum);
}
1071
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int T,K;
int sum=0;
int n1,b,t,n2;
cin>>T>>K;
vector <int> ve1;
vector <int> ve2;
vector <int> ve3;
vector <int> ve4;
for(int i=0; i<K; i++)
{
cin>>n1>>b>>t>>n2;
ve1.push_back(n1);
ve2.push_back(b);
ve3.push_back(t);
ve4.push_back(n2);
}
sum=T;
for(int i=0; i<K; i++)
{
if(sum>=ve3[i])
{
if(ve2[i]==1)
{
if(ve1[i]<ve4[i])
{
cout<<"Win ";
sum+=ve3[i];
cout<<ve3[i]<<"!"<<" Total = "<<sum<<"."<<endl;
}
else
{
cout<<"Lose ";
sum-=ve3[i];
cout<<ve3[i]<<"."<<" Total = "<<sum<<"."<<endl;
}
}
if(ve2[i]==0)
{
if(ve1[i]>ve4[i])
{
cout<<"Win ";
sum+=ve3[i];
cout<<ve3[i]<<"!"<<" Total = "<<sum<<"."<<endl;
}
else
{
cout<<"Lose ";
sum-=ve3[i];
cout<<ve3[i]<<"."<<" Total = "<<sum<<"."<<endl;
}
}
if(sum==0)
{
cout<<"Game Over.";
break;
}
}
else
cout<<"Not enough tokens. Total = "<<sum<<"."<<endl;
}
}
1072
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n,m,h=0;
int k;
int sum,sum1;
cin>>n>>m;
string str,str1,name;
map<string,int> mp;
map<string,int> mp1;
vector <string> ve;
vector <string> ve1;
for(int i=0; i<m; i++)
{
cin>>str;
mp[str]=1;
}
for(int i=0; i<n; i++)
{
cin>>name>>k;
sum=0;
for(int j=0; j<k; j++)
{
cin>>str1;
if(mp[str1]==1)
{
ve.push_back(str1);
sum+=1;
}
}
if(sum>0)
{
ve1.push_back(name);
mp1[name]=sum;
}
}
for(int i=0; i<ve1.size(); i++)
{
cout<<ve1[i]<<":";
for(int m=0; m<mp1[ve1[i]]; m++)
{
cout<<" "<<ve[h];
h++;
}
cout<<"\n";
}
cout<<ve1.size()<<" "<<ve.size();
}
1073
#include<iostream>
#include<set>
using namespace std;
int main()
{
set<char> v[1001];//是二维数组
char a;
int n,m,i,j,x,y,max=0,p[101][5]={0};
double score[101];
cin>>n>>m;
for(i=0;i<m;i++)
{
cin>>score[i]>>x>>y;
while(y--)
{
scanf(" %c",&a);
v[i].insert(a);//存储每一题的正确答案
}
}
while(n--)
{
double sum=0;
scanf("\n");
for(i=0;i<m;i++)
{
int flag=1;
set<char>s,g=v[i];//g为正确答案
if(i!=0) scanf(" ");
scanf("(%d",&x);
while(x--)
{
scanf(" %c",&a);
s.insert(a);//所选选项
}
scanf(")");
if(s==v[i])
sum+=score[i]; //如果选择与正确答案完全一致,则得到该题全部分数。
else //否则,需判断是否有错选的选项,若有,不得分,若无,得该题一半分数。
{
for(auto it=s.begin();it!=s.end();it++) //遍历该题有无错选的选项。
{
if(v[i].find(*it)==v[i].end())
{
flag=0; //如果选择的选项不属于正确选项,用flag=0做标记。
p[i][*it-'a']++; //统计错选选项出现次数。
if(p[i][*it-'a']>max)
max=p[i][*it-'a'];//存储最大次数
}
}
for(auto ot=g.begin();ot!=g.end();ot++) //遍历该题有无漏选的选项。
{
if(s.find(*ot)==s.end())//在全集中找不到的选项
{
p[i][*ot-'a']++; //统计漏选选项出现次数。
if(p[i][*ot-'a']>max)
max=p[i][*ot-'a'];
}
}
if(flag==1)
sum+=score[i]/2.0; //如果flag=1,说明未有错选的选项(只是漏选),可得该题一半分数。
}
}
printf("%.1f\n",sum);
}
if(max==0)
cout<<"Too simple";
else
{
for(i=0;i<m;i++)
{
for(j=0;j<5;j++)
{
if(p[i][j]==max)
printf("%d %d-%c\n",max,i+1,j+'a');
}
}
}
return 0;
}
1074
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
string n1,n2,n3;
int pos=0;
int x,y=0,m,n;
cin>>n1>>n2>>n3;
vector<int> ve1;
vector<int> ve2;
n2.insert(0,n1.length()-n2.length(),'0');
n3.insert(0,n1.length()-n3.length(),'0');
reverse(n1.begin(),n1.end());
reverse(n2.begin(),n2.end());
reverse(n3.begin(),n3.end());
for(int i=0; i<n1.length(); i++)
{
if(n2[i]==0&&n3[i]==0)
{
ve1.push_back(0);
break;
}
m=(n2[i]+n3[i]+y-'0'-'0');
n=(n1[i]-'0');
if(n==0)
n=10;
x=m%n;
y=m/n;
ve1.push_back(x);
}
ve1.push_back(y);
for(int i=ve1.size()-1; i>=0; i--)
{
if(ve1[i]!=0)
{
pos=i;
break;
}
}
for(int i=pos; i>=0; i--)
cout<<ve1[i];
}
1075
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,k,sum=0;
int beginad;
cin>>beginad>>n>>k;
int address;
int data[100000];
int next[100000];
int a[100000];
vector<int>ve1;
vector<int>ve2;
vector<int>ve3;
vector<int>ve4;
vector<int>ve5;
for(int i=0; i<n; i++)
{
cin>>address;
cin>>data[address]>>next[address];//a[i].address>>a[i].data>>a[i].next
}
for(int i=0; i<n; i++)
{
if(beginad!=-1)
{
a[sum++]=beginad;
beginad=next[beginad];
}
}
for(int i=0; i<sum; i++)
{
if(data[a[i]]<0)
ve1.push_back(a[i]);
else if(data[a[i]]>k)
ve3.push_back(a[i]);
else
ve2.push_back(a[i]);
}
for(int m=0;m<ve1.size();m++)
ve4.push_back(ve1[m]);
for(int m=0;m<ve2.size();m++)
ve4.push_back(ve2[m]);
for(int m=0;m<ve3.size();m++)
ve4.push_back(ve3[m]);
for(int i=0;i<sum;i++)
{
printf("%05d %d ",ve4[i],data[ve4[i]]);
if(i!=sum-1)
printf("%05d\n",ve4[i+1]);
else
cout<<-1<<endl;
}
}
1076
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string str;
int n;
cin>>n;
getline(cin,str);//如果不加这一句,换行也被当成一行
vector <string> ve;
vector <int> ve1;
for(int i=0;i<n;i++)
{
getline(cin,str);
ve.push_back(str);
}
for(int i=0;i<n;i++)
{
for(int m=0;m<str.length();m++)
{
if(ve[i][m]=='T')
ve1.push_back(ve[i][m-2]-'A'+1);
}
}
for(int i=0;i<n;i++)
cout<<ve1[i];
}
1077
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
bool cmp(int a,int b)
{
if(a<b)
return true;
else
return false;
}
using namespace std;
int main()
{
int n,m;
double a,sum;
double grade,endgrade;
cin>>n>>m;
vector <int> ve;
vector <double> ve1;
for(int i=0;i<n;i++)
{
sum=0;
a=0;
endgrade=0;
for(int k=0;k<n;k++)
{
cin>>grade;
if((grade>=0)&&(grade<=m))
ve.push_back(grade);
}
sort(ve.begin()+1,ve.end(),cmp);
for(int h=0;h<ve.size();h++)
{
if(h>1&&h<ve.size()-1)
sum+=ve[h];
}
endgrade=((sum/(ve.size()-3))+ve[0])/2.0;
ve1.push_back(endgrade);
ve.clear();
}
for(int i=0;i<ve1.size();i++)
cout<<round(ve1[i])<<endl;
}
1078
#include <iostream>
using namespace std;
int main()
{
char c;
int j;
cin>>c;
int num1;
string s,num;
getchar();
getline(cin,s);
if(c=='C')
{
for (int i = 0; i < s.length(); i = j)
{
for ( j = i ; j < s.length() && s[j] == s[i]; j++);
{
if((j-i)!=1)
cout<<j-i;
cout<<s[i];
}
}
}
if(c=='D')
{//5T2h4is i5s a3 te4st CA3a as10Z
for(int i=0;i<s.length();i++)
{
if(s[i]>='0'&&s[i]<='9')
{
num+=s[i];
}
else
{
if(num.length()>0)
{
num1=stoi(num);
for(int h=0;h<num1;h++)
cout<<s[i];
}
else
cout<<s[i];
num="";
}
}
}
}
1079
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string str1,str2,str3,str4;
int x=0,y=0;
cin>>str1;
str2=str1;
reverse(str1.begin(),str1.end());
for(int k=0; k<11; k++)
{
x=y=0;
str3="";
if(str1==str2)
{
cout<<str1<<" is a palindromic number.";
break;
}
if(k==10)
{
cout<<"Not found in 10 iterations.";
break;
}
cout<<str2<<" + "<<str1<<" = ";
for(int i=0; i<str1.length(); i++)
{
x=(str1[i]+str2[i]+y-'0'-'0')%10;
y=(str1[i]+str2[i]+y-'0'-'0')/10;
str3+='0'+x;
}
if(y>0)
str3+='0'+y;
str1=str3;
reverse(str3.begin(),str3.end());
str2=str3;
cout<<str2<<endl;
}
}
1080
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
struct node {
string name;
int gp, gm, gf, g;
};
bool cmp(node a, node b) {
return a.g != b.g ? a.g > b.g : a.name < b.name;
}
map<string, int> idx;
int main() {
int p, m, n, score, cnt = 1;
cin >> p >> m >> n;
vector<node> v, ans;
string s;
for (int i = 0; i < p; i++) {
cin >> s >> score;
if (score >= 200) {
v.push_back(node{s, score, -1, -1, 0});
idx[s] = cnt++;
}
}
for (int i = 0; i < m; i++) {
cin >> s >> score;
if (idx[s] != 0)
v[idx[s] - 1].gm = score;//只存大于200的人的编程成绩
}
for (int i = 0; i < n; i++) {
cin >> s >> score;
if (idx[s] != 0) {
int temp = idx[s] - 1;//只存大于200的人的期末综合成绩
v[temp].gf = v[temp].g = score;
if (v[temp].gm > v[temp].gf)//若不大则不用更新
v[temp].g = int(v[temp].gm * 0.4 + v[temp].gf * 0.6 + 0.5);//不用使用round
}
}
for (int i = 0; i < v.size(); i++)
if (v[i].g >= 60)
ans.push_back(v[i]);
sort(ans.begin(), ans.end(), cmp);
for (int i = 0; i < ans.size(); i++)
printf("%s %d %d %d %d\n", ans[i].name.c_str(), ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g);
return 0;
}
1081
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
int a,b,c;
cin>>n;
string str;
getline(cin,str);
vector <string> ve;
for(int i=0; i<n; i++)
{
getline(cin,str);
ve.push_back(str);
}
for(int m=0; m<n; m++)
{
a=b=c=0;
for(int i=0; i<ve[m].size(); i++)
{
if(ve[m][i]>=48&&ve[m][i]<=57)
a++;
if((ve[m][i]>=65&&ve[m][i]<=90)||(ve[m][i]>=97&&ve[m][i]<=122))
b++;
if(ve[m][i]==46)
c++;
}
if(ve[m].length()<6)
cout<<"Your password is tai duan le."<<endl;
else
{
if((a+b+c)!=ve[m].length())
cout<<"Your password is tai luan le."<<endl;
else
{
if(a>0&&b==0)
cout<<"Your password needs zi mu."<<endl;
if(b>0&&a==0)
cout<<"Your password needs shu zi."<<endl;
if(a>0&&b>0)
cout<<"Your password is wan mei."<<endl;
}
}
}
}
1082
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
struct ath
{
string id;
int x;
int y;
double distance;
}a[10000];
bool cmp(ath a,ath b)
{
if(a.distance<b.distance)
return true;
else
return false;
}
int main()
{
int n;
cin>>n;
vector <ath> ve;
for(int i=0;i<n;i++)
{
cin>>a[i].id>>a[i].x>>a[i].y;
a[i].distance=sqrt(pow(a[i].x,2)+pow(a[i].y,2));
ve.push_back(a[i]);
}
sort(ve.begin(),ve.end(),cmp);
for(int i=0;i<ve.size();i++)
{
if(i==0)
cout<<ve[i].id;
if(i==ve.size()-1)
cout<<" "<<ve[i].id;
}
}
1083
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int n,a,k;
cin>>n;
vector<int>ve;
vector<int>ve1;
set<int> s;
for(int i=0; i<n; i++)
{
cin>>a;
ve.push_back(a);
}
for(int i=0; i<n; i++)
{
k=fabs(ve[i]-i-1);
ve1.push_back(k);
s.insert(k);
}
auto it=s.end();
it--;
while(it!=s.begin())
{
a=count(ve1.begin(),ve1.end(),*it);
if(a!=1)
cout<<*it<<" "<<a<<endl;
it--;
}
a=count(ve1.begin(),ve1.end(),*it);
if(a!=1)
cout<<*it<<" "<<a<<endl;
}
1084
#include <iostream>
using namespace std;
int main()
{
string s;
int n, j;
cin >> s >> n;
for (int cnt = 1; cnt < n; cnt++)
{
string t;
for (int i = 0; i < s.length(); i = j)
{//从上次不同的地方开始
for ( j = i ; j < s.length() && s[j] == s[i]; j++)
;//一直对比到不同的位置
t += to_string((s[i] - '0') * 10 + j - i);//每次都是临时标记一次
//j-i是计算相同的个数 to_string((s[i] - '0') * 10是相同的数字
}
s = t;
}
cout << s;
}
1085
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
struct ph1
{
string name;
int ren,sumgrade;
};
bool cmp(ph1 a,ph1 b)
{
if(a.sumgrade!=b.sumgrade)
return a.sumgrade>b.sumgrade;
else if(a.ren!=b.ren)
return a.ren<b.ren;
else
return a.name<b.name;
}
int main()
{
int n,grade,pos;
string name,id;
cin>>n;
vector<ph1> ve2;
set<string>s;
map<string,double> mp;
map<string,int> mp1;
for(int i=0; i<n; i++)
{
cin>>id>>grade>>name;
transform(name.begin(),name.end(),name.begin(),::tolower);
mp1[name]++;
if(id[0]=='T')
mp[name]+=grade*1.5;
if(id[0]=='B')
mp[name]+=grade/1.5;
if(id[0]=='A')
mp[name]+=grade;
}
for (auto it = mp1.begin(); it != mp1.end(); it++)
ve2.push_back(ph1{it->first, mp1[it->first],(int)mp[it->first]});
sort(ve2.begin(),ve2.end(),cmp);
cout<<ve2.size()<<endl;
for(int i=0; i<ve2.size(); i++)
{
if(i==0)
pos=1;
if(ve2[i-1].sumgrade!=ve2[i].sumgrade)
pos=i+1;
cout<<pos;
cout<<" "<<ve2[i].name<<" "<<ve2[i].sumgrade<<" "<<ve2[i].ren<<endl;
}
}
1086
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=a*b;
string str=to_string(c);
reverse(str.begin(),str.end());
c=stoi(str);
cout<<c;
}
1087
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main()
{
int n;
cin>>n;
int a;
vector<int> ve;
set<int>s;
for(int i=1;i<n+1;i++)
{
a=(i/2)+(i/3)+(i/5);
s.insert(a);
}
cout<<s.size();
}
1088
#include <iostream>
#include <math.h>
#include <map>
using namespace std;
void gx(double a,double b)
{
if(a>b)
cout<<"Gai";
else if(a==b)
cout<<"Ping";
else
cout<<"Cong";
}
int main()
{
int a,b,x,y;
double jia=0,yi,bin,m,c,k;
cin>>m>>x>>y;
map<int,string> mp;
for(int a=0; a<10; a++)
{
for(int b=0; b<10; b++)
{
k=(10*b+a);
c=k/y;
if(fabs(9*a-9*b)==x*c)
{
jia=10*a+b;
yi=10*b+a;
bin=c;
}
}
}
if(jia==0)
cout<<"No Solution";
else
{
cout<<jia<<" ";
gx(m,jia);
cout<<" ";
gx(m,yi);
cout<<" ";
gx(m,bin);
}
}
1089
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n+1);
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
vector<int> lie, a(n + 1, 1);
a[i] = a[j] = -1;
for (int k = 1; k <= n; k++)
if (v[k] * a[abs(v[k])] < 0) lie.push_back(k);
if (lie.size() == 2 && a[lie[0]] + a[lie[1]] == 0) {
cout << i << " " << j;
return 0;
}
}
}
cout << "No Solution";
return 0;
}
1090
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int n,m,x,y;
cin>>n>>m;
map<int,vector<int> > mp;
vector<int> v;
for(int i=0; i<n; i++)
{
cin>>x>>y;
mp[x].push_back(y);
mp[y].push_back(x);
}
for(int i=0; i<m; i++)
{
v.clear();
int b=0;
int pos=0;
int a[100000]= {0};
cin>>x;
for(int k=0; k<x; k++)
{
cin>>y;
a[y]=1;
v.push_back(y);
}
for(int h=0; h<v.size(); h++)
{
for(int k=0; k<mp[v[h]].size(); k++)
{
b=a[mp[v[h]][k]];
if(b==1)
pos=1;
}
}
if(pos==1)
cout<<"No"<<endl;
if(pos==0)
cout<<"Yes"<<endl;
}
}
1091
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
int main()
{
int m,n,k,a,b,sum;
int c,d;
cin>>m;
string str1,str2;
vector<int> ve;
vector<int> ve1;
map <int,int> mp;
for(int i=0; i<m; i++)
{
cin>>n;
ve.push_back(n);
}
for(int i=0; i<m; i++)
{
for(int k=1; k<10; k++)
{
sum=0;
c=ve[i];
d=k*ve[i]*ve[i];
str1=to_string(c);
str2=to_string(d);
a=str1.length();
b=str2.length();
while(a>0)
{
a--;
b--;
if(str1[a]==str2[b])
sum++;
}
if(sum==str1.length())
{
ve1.push_back(k);
mp[i]=k;
break;
}
}
}
for(int i=0; i<m; i++)
{
if(mp[i]==0)
cout<<"No"<<endl;
else
cout<<mp[i]<<" "<<mp[i]*ve[i]*ve[i]<<endl;
}
}
1092
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
int m,n,h,maxp=0;
cin>>m>>n;
vector<vector<int>> ve;
vector <int> ve1;
vector <int> ve2;
map<int,int> mp;
for(int i=0; i<n; i++)
{
ve1.clear();
for(int k=0; k<m; k++)
{
cin>>h;
ve1.push_back(h);
}
ve.push_back(ve1);
}
for(int k=0; k<m; k++)
{
for(int i=0; i<n; i++)
{
mp[k+1]+=ve[i][k];
}
}
for(int i=0;i<mp.size();i++)
{
if(maxp<mp[i+1])
maxp=mp[i+1];
}
cout<<maxp<<endl;
for(int i=0;i<mp.size();i++)
{
if(maxp==mp[i+1])
ve2.push_back(i+1);
}
for(int i=0;i<ve2.size();i++)
{
if(i!=0)
cout<<" ";
cout<<ve2[i];
}
}
1093
#include <iostream>
using namespace std;
int main()
{
string str1,str2;
getline(cin,str1);
getline(cin,str2);
string str3=str1+str2;
string str4="";
for(int i=0;i<str3.length();i++)
{
if((str4.find(str3[i])==str4.npos))
str4+=str3[i];
}
cout<<str4;
}
1094
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool isPrime(long long number)
{
for(long long i=2; i*i<=number; i++)
if (number%i==0)
return false;
return true;
}
int main()
{
int l,k;
long long b;
cin>>l>>k;
string str,a;
cin>>str;
for(int i=0; i<l+1; i++)
{
if(i+k>l)
{
cout<<"404";
break;
}
if(i+k<=l)
{
string a=str.substr(i,k);
b=stoi(a);
if(isPrime(b))
{
cout<<a;
break;
}
}
}
}
1095
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct node
{
string t;
int value;
};
bool cmp(const node &a, const node &b)
{
return a.value != b.value ? a.value > b.value : a.t < b.t;
}
int main()
{
int n, k, num;
string s;
cin >> n >> k;
vector<node> v(n);
for (int i = 0; i < n; i++)
cin >> v[i].t >> v[i].value;
for (int i = 1; i <= k; i++)
{
cin >> num >> s;
cout<<"Case "<<i<<": "<<num<<" "<<s<<endl;
vector<node> ans;
int cnt = 0, sum = 0;
if (num == 1)
{
for (int j = 0; j < n; j++)
if (v[j].t[0] == s[0])
ans.push_back(v[j]);
}
else if (num == 2)
{
for (int j = 0; j < n; j++)
{
if (v[j].t.substr(1, 3) == s)
{
cnt++;
sum += v[j].value;
}
}
if (cnt != 0)
printf("%d %d\n", cnt, sum);
}
else if (num == 3)
{
unordered_map<string, int> m;//用map会超时
for (int j = 0; j < n; j++)
if (v[j].t.substr(4, 6) == s)
m[v[j].t.substr(1, 3)]++;
for (auto it : m)
ans.push_back({it.first, it.second});
}
sort(ans.begin(), ans.end(),cmp);
for (int j = 0; j < ans.size(); j++)
printf("%s %d\n", ans[j].t.c_str(), ans[j].value);//用cout会超时
if (((num == 1 || num == 3) && ans.size() == 0) || (num == 2 && cnt == 0))
printf("NA\n");
}
return 0;
}