PAT B1-95【练习帖】【纪念帖】【10天】【完结】【不全】

B1001

#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;
}

在这里插入图片描述

B1002

#include <iostream>
#include <string>
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();
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'];
	cout<<str<<" ";
	}
	}

在这里插入图片描述

B1003

#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;
}

在这里插入图片描述

B1004

#include <iostream>
#include <algorithm>
using namespace std;
struct student{
string name;
string id;
int grade;
}stdu[100];
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;
}

在这里插入图片描述

B1005

#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;
}

在这里插入图片描述

B1006

#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;
}

在这里插入图片描述

B1007

#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;
}

在这里插入图片描述

B1008

#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];
}
}

在这里插入图片描述

B1009

 #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();
        }
    }

在这里插入图片描述

B1010

    #include <iostream>
  #include <vector>
    //此题不能用map 因为不知道first的值是否会是一样的
    using namespace std;
    int main()
    {
        int cof,index;
        vector<int> ve1;
        vector<int> ve2;
        cin>>cof>>index;
        if(cof==0&&index==0)
        {
            ve1.push_back(0);
            ve2.push_back(0);
        }
        if(index!=0)
        {
        ve1.push_back(cof*index);
        ve2.push_back(index-1);
        }
        while(cin>>cof>>index)
        {
            if(cof==0&&index==0)
           {
            ve1.push_back(0);
            ve2.push_back(0);
        }
        if(index!=0)
        {
            ve1.push_back(cof*index);
        ve2.push_back(index-1);
        }
        }
        for(int i=0;i<ve1.size();i++)
        {
            if(i==0)
                cout<<ve1[i]<<" "<<ve2[i];
            else
                cout<<" "<<ve1[i]<<" "<<ve2[i];
        }
    }

在这里插入图片描述

B1011

#include <iostream>
using namespace std;
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++)
{
    if(m[i]==1)
        cout<<"Case #"<<i<<": true"<<endl;
    else
        cout<<"Case #"<<i<<": false"<<endl;
} 
}

在这里插入图片描述

B1012

#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";
}

在这里插入图片描述

B1013

#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<100000;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 if(sum%10==0)
        cout<<"\n";
     else
        cout<<" "<<ve[i-1];
    }
    }

在这里插入图片描述

B1014

#include <iostream>
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;
    for(int i=0;i<60;i++)
    {
        if(str1[i]==str2[i]&&str1[i]>=65&&str1[i]<=90)//注意范围
        {
            a[count]=str1[i];
            count+=1;
        }
            if(count==2)
            break;
    }
    for(int i=0;i<60;i++)
    {
        if(str3[i]==str4[i]&&((str1[i]>=65&&str1[i]<=90)||(str1[i]>=97&&str1[i]<=122)))
        {
            pos=i;
            break;
        }
    }
    string days[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    if(pos<10)
    cout<<days[a[0]-'A']<<" "<<a[1]-'A'+10<<":0"<<pos;
    else
    cout<<days[a[0]-'A']<<" "<<a[1]-'A'+10<<":"<<pos;
    }

在这里插入图片描述

B1015

#include <iostream>
#include <vector>
#include<algorithm>//调用sort
using namespace std;
struct student
{
    string id;
    int de;
    int cai;
}stu[10000];
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;
cin>>n>>l>>h;
int sum1=0,sum2=0,sum3=0,sum4=0;
vector <student> ve1;//给不同类学生分层
vector <student> ve2;
vector <student> ve3;
vector <student> ve4;
for(int i=0;i<n;i++)
{
  cin>>stu[i].id>>stu[i].de>>stu[i].cai;
  if(stu[i].de>=l&&stu[i].cai>=l)
  {
    if(stu[i].de>=h&&stu[i].cai>=h)
    {
       ve1.push_back(stu[i]);
       sum1+=1;
    }
    else if(stu[i].de>=h&&stu[i].cai<h)
    {
        ve2.push_back(stu[i]);
        sum2+=1;
    }
    else if(stu[i].de<h&&stu[i].cai<h&&(stu[i].de>=stu[i].cai))
    {
      ve3.push_back(stu[i]);
      sum3+=1;
    }
    else
    {
        ve4.push_back(stu[i]);
        sum4+=1;
    }
  }
}
  sort(ve1.begin(),ve1.end(),cmp);
  sort(ve2.begin(),ve2.end(),cmp);
  sort(ve3.begin(),ve3.end(),cmp);
  sort(ve4.begin(),ve4.end(),cmp);
  cout<<sum1+sum2+sum3+sum4<<endl;
  for(int i=0;i<ve1.size();i++)
  {
      cout<<ve1[i].id<<" "<<ve1[i].de<<" "<<ve1[i].cai<<endl;
  }
  for(int i=0;i<ve2.size();i++)
  {
      cout<<ve2[i].id<<" "<<ve2[i].de<<" "<<ve2[i].cai<<endl;
  }
  for(int i=0;i<ve3.size();i++)
  {
      cout<<ve3[i].id<<" "<<ve3[i].de<<" "<<ve3[i].cai<<endl;
  }
  for(int i=0;i<ve4.size();i++)
  {
      cout<<ve4[i].id<<" "<<ve4[i].de<<" "<<ve4[i].cai<<endl;
  }
}

在这里插入图片描述

B1016

#include <iostream>
#include <vector>
using namespace std;
int main()
{
string A,B;
int Da,Db,m,n;
cin>>A>>Da>>B>>Db;
vector <char> ve1;
vector <char> ve2;
vector <char> ve3;
for(int i=0;i<A.length();i++)//(A[i]==Da+30),(A[i]==Da)都不对,搞错了ASCii值是48
{
if(A[i]-'0'==Da)
{
    ve1.push_back(A[i]);
}
}
for(int i=0;i<B.length();i++)
{
if(B[i]-'0'==Db)
{
    ve2.push_back(B[i]);
}
}
m=max(ve1.size(),ve2.size());
n=min(ve1.size(),ve2.size());
if(m>ve1.size())
{
 for(int i=0;i<m;i++)
{
if(i<m-n)
    ve3.push_back('0');
else
{
   for(int i=0;i<m;i++)
    {
      ve3.push_back(ve1[i]);
    }
}
}
}
if(m>ve2.size())
{
 for(int i=0;i<m;i++)
{
if(i<m-n)
    ve3.push_back('0');
else
{
    for(int i=0;i<m;i++)
    {
      ve3.push_back(ve2[i]);
    }
}
}
}
cout<<ve1.size()<<" "<<ve2.size()<<endl;
for(int i=0;i<m;i++)
{
    if(m>ve2.size())
    cout<<ve1[i]+ve3[i]-96;
    if(m>ve1.size())
    cout<<ve2[i]+ve3[i]-96;
}
}

在这里插入图片描述

B1017

#include
#include
using namespace std;
int main()
{
string a;
vector ve;
int b,c=0,d=0;
cin>>a>>b;
for(int i=0; i<a.length(); i++)
{
c=(a[i]-‘0’+10d)/b;
ve.push_back©;
d=(a[i]-‘0’+10
d)%b;
}
if(ve[0]!=0)
cout<<ve[0];
for(int i=1; i<ve.size(); i++)
cout<<ve[i];
cout<<" "<<d;
}
在这里插入图片描述

B1018

#include <iostream>
#include <map>//用map代表对应获胜次数
#include <vector>
using namespace std;
int main()
{
    int n,sum=0;//sum为平局次数
    char a,b,c;//用来获得输入
    char x='B',y='B';//用来确定哪个字符最小
    cin>>n;
    vector<char> ve1;
    vector<char> ve2;
    map<char,int> mp1;
    map<char,int> mp2;
    getchar();
    for(int i=0; i<n; i++)
    {
        scanf("%c%c%c",&a,&c,&b);
        ve1.push_back(a);
        ve2.push_back(b);
        getchar();
    }
    for(int i=0; i<n; i++)
    {
        if(ve1[i]=='C'&&ve2[i]=='B')
        {
            mp2['B']+=1;
        }
        if(ve1[i]=='C'&&ve2[i]=='C')
        {
            sum+=1;
        }
        if(ve1[i]=='C'&&ve2[i]=='J')
        {
            mp1['C']+=1;
        }
        if(ve1[i]=='B'&&ve2[i]=='B')
        {
            sum+=1;
        }
        if(ve1[i]=='B'&&ve2[i]=='C')
        {
            mp1['B']+=1;
        }
        if(ve1[i]=='B'&&ve2[i]=='J')
        {
            mp2['J']+=1;
        }
        if(ve1[i]=='J'&&ve2[i]=='B')
        {
            mp1['J']+=1;
        }
        if(ve1[i]=='J'&&ve2[i]=='C')
        {
            mp2['C']+=1;
        }
        if(ve1[i]=='J'&&ve2[i]=='J')
        {
            sum+=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
            x='J';
    }
    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';
    }
    cout<<mp1['J']+mp1['C']+mp1['B']<<" "<<sum<<" "<<n-(mp1['J']+mp1['C']+mp1['B']+sum)<<endl;
    cout<<mp2['J']+mp2['C']+mp2['B']<<" "<<sum<<" "<<n-(mp2['J']+mp2['C']+mp2['B']+sum)<<endl;
    cout<<x<<" "<<y;
}

在这里插入图片描述

B1019

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp1(int a,int b)
{
    if(a>b)
        return true;
    else
        return false;
}
bool cmp2(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];
    q=n/1000;
    b=n/100-10*q;
    s=n/10-100*q-10*b;
    g=n%10;
    vector<int> ve1;
    ve1.push_back(q);
    ve1.push_back(b);
    ve1.push_back(s);
    ve1.push_back(g);
    if(q==b==s==g)
        cout<<n<<"-"<<n<<"="<<"0"<<endl;
    for(int i=0;i<1000;i++)
    {
        sort(ve1.begin(),ve1.end(),cmp1);
        z=ve1[0]*1000+ve1[1]*100+ve1[2]*10+ve1[3];
        sort(ve1.begin(),ve1.end(),cmp2);
        y=ve1[0]*1000+ve1[1]*100+ve1[2]*10+ve1[3];
        n=z-y;
        if(y>1000)
        cout<<z<<"-"<<y<<"="<<n<<endl;
        else//最多只有一位是空的
        cout<<z<<"-0"<<y<<"="<<n<<endl;
        if(n==6174)
            break;
        q=n/1000;
        b=n/100-10*q;
        s=n/10-100*q-10*b;
        g=n%10;
        ve1.clear();
        ve1.push_back(q);
        ve1.push_back(b);
        ve1.push_back(s);
        ve1.push_back(g);
    }
}

在这里插入图片描述

B1020

#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++)
    {
        if(d-sum2>0)
        {
            sum2+=ve[i].store;
            if(sum2<20)
            {
                sum1+=ve[i].store*ve[i].uniprice;
            }
            else
            {
                sum1+=(d-sum3)*ve[i].uniprice;
                cout<<fixed<<setprecision(2)<<sum1<<endl;
            }
            sum3=sum2;
        }
    }
}

在这里插入图片描述

B1021

#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;
        }
}

在这里插入图片描述

B1022

#include <iostream>
using namespace std;
int main()
{
    int a,b,d,y,num=0;
    int z[30];
    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];
}

在这里插入图片描述

B1023

#include <iostream>
#include <map>
using namespace std;
int main()
{
    int sum1,sum2,pos;
    map<int,int> mp;
    for(int i=0; i<10; i++)
    {
        cin>>mp[i];
    }
        if(mp[0]<1)
        {

            for(int i=1; i<10; i++)
            {
                sum1=0;
                while(sum1<=mp[i])
                {
                    cout<<i;
                    sum1++;
                }
            }
        }
        else
        {

            for(int i=1; i<10; i++)
            {
                pos=i;
                if(mp[i]>=1)
                    break;

            }
            cout<<pos;
            for(int i=0; i<10; i++)
            {
                sum2=0;
                if(i==pos)
                    sum2=1;
                while(sum2<mp[i])
                {
                    cout<<i;
                    sum2++;
                }
            }
        }
    }

在这里插入图片描述

B1024

#include <iostream>
#include <map>
#include <math.h>
using namespace std;
int main()
{
    int inte1,inte2,inte3;
    char a,b,c,d;
    //a决定第一个是否输出符号,inte3决定是0.还是向右移动
    cin>>a>>inte1>>b>>inte2>>c>>d>>inte3;
    string str=to_string(inte2);
    if(a=='-')
        cout<<a;
    if(d=='-')
    {
        cout<<"0.";
        for(int i=1; i<inte3; i++)
            cout<<"0";
        cout<<inte1<<inte2;
    }
    else
    {
        //如果在inte2的位数小于inte3的情况下,正常输出补0就好
        //如果位数大于inte3,那么还要加入小数点再进行输出

        if(str.length()<=inte3)
        {
            cout<<inte1<<inte2;
            for(int i=str.length(); i<inte3; i++)
                cout<<"0";
        }
        else
        {
            cout<<inte1;
            for(int i=0; i<inte3; i++)
                cout<<str[i];
            cout<<".";
            for(int i=inte3; i<str.length(); i++)
                cout<<str[i];
        }
    }
}

在这里插入图片描述

B1025

#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[10000];
    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<n-n%k; i+=k)
    {
        reverse(begin(a)+i,begin(a)+i+k);
    }
    for(int i=0; i<n; i++)
    {
        if(i!=n-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);
    }
}

B1026

#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;
   cout<<a<<":"<<b<<":"<<c;
}

在这里插入图片描述

B1027

#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<5;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";
}
if((n-sum)!=0)
cout<<n-sum;
}

在这里插入图片描述

B1028

#include <iostream>
#include <vector>//结构体插入 通过if检测是否年月日都满足条件
#include <algorithm>
using namespace std;
struct people
{
    string name;
    int y;
    int m;
    int d;
} p[100000];
bool cmp(people a,people b)
{
    if(a.y!=b.y)
    {
        if(a.y>b.y)
            return true;
        else
            return false;
    }
    else
    {
        if(a.m!=b.m)
        {
            if(a.m>b.m)
                return true;
            else
                return false;
        }
        else
        {
            if(a.d>b.d)
                return true;
            else
                return false;
        }
    }
}
int main()
{
    int n,a;
    char b,c;
    cin>>n;
    vector <people> ve;
    for(int i=0; i<n; i++)
    {
        cin>>p[i].name>>p[i].y>>b>>p[i].m>>c>>p[i].d;
    }
    for(int i=0; i<n; i++)
    {
        if(p[i].y==1814)
        {
            //检测1814年时是否满足条件
            if(p[i].m>=9)
            {
                if(p[i].m==9)
                {
                    if(p[i].d>=6&&p[i].d<=30)
                        ve.push_back(p[i]);
                }
            }
        }
        if(p[i].y==2014)
        {
            //检测2014年时是否满足条件
            if(p[i].m<=9)
            {
                if(p[i].m==9)
                {
                    if(p[i].d<=6)
                        ve.push_back(p[i]);
                }
            }
        }
        if(p[i].y<2014&&p[i].y>1814)
        {
            if(p[i].m>=1&&p[i].m<=12)
            {
                if((p[i].m==1||p[i].m==3||p[i].m==5||p[i].m==7||p[i].m==8||p[i].m==10||p[i].m==12)&&p[i].d<=30&&p[i].d>=1)
                    ve.push_back(p[i]);
                if((p[i].m==4||p[i].m==6||p[i].m==9||p[i].m==11)&&p[i].d<=30&&p[i].d>=1)
                    ve.push_back(p[i]);
                if(p[i].m==2&&(p[i].y%4==0)&&p[i].d<=29&&p[i].d>=1)
                    ve.push_back(p[i]);
                if(p[i].m==2&&(p[i].y%4!=0)&&p[i].d<=28&&p[i].d>=1)
                    ve.push_back(p[i]);
            }
        }
    }
    sort(ve.begin(),ve.end(),cmp);
    a=ve.size();
    cout<<a<<" "<<ve[a-1].name<<" "<<ve[0].name;
}

在这里插入图片描述

B1029

  #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    string str1;
    string str2;
    int pos1=0,pos2=0;
    cin>>str1>>str2;
    vector<char> ve;
    transform(str1.begin(),str1.end(),str1.begin(),::toupper);
    transform(str2.begin(),str2.end(),str2.begin(),::toupper);
    while(pos1<str1.length()&&pos2<str2.length())
    {
        if(str1[pos1]!=str2[pos2])
        {
            ve.push_back(str1[pos1]);
            pos1+=1;
        }
        else
        {
            pos1+=1;
            pos2+=1;
        }
    }
    // 删除重复单词
    sort(ve.begin(), ve.end());
    auto end_unique = unique(ve.begin(), ve.end());
    ve.erase(end_unique, ve.end());
    for(int i=0; i<ve.size(); i++)
        cout<<ve[i];
}

在这里插入图片描述

B1030

#include <iostream>
#include <vector>
#include <algorithm>
bool cmp(int a,int b)
{
    if(a<b)
    return true;
    else
        return false;

}
using namespace std;
int main()
{
    int n,p,m,sum=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(),cmp);
    for(int i=0;i<n;i++)
    {
        if(p*ve[0]>=ve[i])
            sum+=1;
    }
    cout<<sum;
}

在这里插入图片描述

B1031

#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct id
{
    string str;
    int length=0;

} a[100];
int main()
{
    int n,k=0;//k是计算有效个数
    cin>>n;
    int b[17]= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    int sum[100]={0};
    map<int,char> mp;
    vector<string>ve;
    mp[0]='1',mp[1]='0',mp[2]='X',mp[3]='9',mp[4]='8',mp[5]='7',mp[6]='6',mp[7]='5',mp[8]='4',mp[9]='3',mp[10]='2';
    for(int i=0; i<n; i++)
    {
        cin>>a[i].str;
    }
    for(int m=0; m<n; m++)
    {
        for(int i=0; i<17; i++)
        {
            if(a[m].str[i]>=48&&a[m].str[i]<=57)
                a[m].length+=1;
        }
    }
    for(int m=0; m<n; m++)
    {
        if(a[m].length==17)
        {
            for(int i=0; i<17; i++)
            {
                sum[k]+=(a[m].str[i]-'0')*b[i];
            }
            sum[k]%=11;
            if(mp[sum[k]]!=a[m].str[17])
                ve.push_back(a[m].str);
                k+=1;
        }
        else
            ve.push_back(a[m].str);
    }
    if(ve.size()==0)
        cout<<"All passed";
    else
    {
        for(int i=0;i<ve.size();i++)
        cout<<ve[i]<<endl;
    }
}

在这里插入图片描述

B1032

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
struct compete
{
    int id;
    int grade;

} a[10000];
bool cmp(compete a,compete b)
{
    if(a.id<b.id)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,m=0,maxgrade=0,maxid=0;
    cin>>n;
    //利用vector进行对编号的排序
    //再开一个vector去重,利用map来进行计数
    vector<compete>ve;
    vector<int>ve1;
    map<int,int> mp;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].id>>a[i].grade;
        ve.push_back(a[i]);
        ve1.push_back(a[i].id);
    }
    sort(ve.begin(),ve.end(),cmp);
    sort(ve1.begin(), ve1.end());
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0; i<ve1.size(); i++)
    {
        while(m<ve.size())
        {
            if(ve1[i]==ve[m].id)
            {
                mp[ve1[i]]+=ve[m].grade;
                m+=1;
            }
            else
                break;
        }
    }
    for(int i=0; i<mp.size(); i++)
    {
        if(mp[i]>maxgrade)
        {
            maxgrade=mp[i];
            maxid=i;
        }
    }
    cout<<maxid<<" "<<maxgrade;
}

在这里插入图片描述

B1033

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool shift(string str)//,44  .46  -45  +43
{
    for(int i=0; i<str.length(); i++)
    {
        if(str[i]==44||str[i]==46||str[i]==45||str[i]==43)
            return true;
    }

    return false;
}
bool caplet(string str)
{
    for(int i=0; i<str.length(); i++)
    {
        if(str[i]>=65&&str[i]<=90)
            return true;
    }

    return false;
}
bool exist(char a,string str)
{
    for(int i=0; i<str.length(); i++)
    {
        if(str[i]==a)
            return true;
    }
    return false;
}
int main()
{
    string str1,str2;
    cin>>str1>>str2;
    vector<char> ve;
    //如果大于0,那么str2
//上档键如果存在,则str2里的所有字符不能输出大写
//如果有大写字母,则str2里的字符不能输出大写,小写
    for(int i=0; i<str2.length(); i++)
    {
        if((shift(str1)==false)&&(caplet(str1)==false))
        {
            if(exist(str2[i],str1)!=true)
                ve.push_back(str2[i]);
        }
        if((shift(str1)==true)&&(caplet(str1)==false))
        {
            if((exist(str2[i],str1)!=true)&&str2[i]<65&&str2[i]>90)
                ve.push_back(str2[i]);
        }
        if((shift(str1)==false)&&(caplet(str1)==true))
        {
            if((exist(str2[i],str1)!=true)&&(exist(str2[i]-32,str1)!=true))
                ve.push_back(str2[i]);
        }
        if((shift(str1)==true)&&(caplet(str1)==true))
        {
            if((exist(str2[i],str1)==false)&&(exist(str2[i]-32,str1)==false)&&(str2[i]<65||str2[i]>90))
                ve.push_back(str2[i]);
        }
    }
    for(int i=0; i<ve.size(); i++)
        cout<<ve[i];
}

在这里插入图片描述

B1034

#include <iostream>
using namespace std;
int main()
{
    int a,c,d,f,k1,k2,l,m,n,x,y;
    int pos1=0,pos2=0,pos3=0,pos4=0;//pos1,pos2,pos3,pos4代表的是公约数
    int m1,n1,d1,f1;//乘积的分子分母
    int m2,n2,d2,f2;
    char b,e;
    cin>>a>>b>>c>>d>>e>>f;
    l=(a*f+c*d)/(f*c);//加法的整数部分
    m=(a*f+c*d)-l*(f*c);//加法小数部分的分子
    x=(a*f-c*d)/(f*c);//减法的整数部分
    y=(a*f-c*d)-x*(f*c);//减法法小数部分的分子
    m1=a*d;
    n1=c*f;
    d1=m1/n1;//乘法的整数部分
    f1=m1-d1*n1;//乘法小数部分的分子
    m2=a*f;
    n2=c*d;
    if(n2<0)
    {
        n2=(-1)*n2;
        m2=(-1)*m2;
    }
    if(n2!=0)
    {
        d2=m2/n2;//除法的整数部分
        f2=m2-d2*n2;//除法小数部分的分子
    }
    n=f*c;
    k1=a/c;
    a=a-k1*c;
    k2=d/f;
    d=d-k2*f;
    //加法部分
    if(k1<0||a<0)
        cout<<"(";
    if((k1!=0)&&(a!=0))
        cout<<k1<<" "<<abs(a)<<b<<c;
    if((k1==0)&&(a!=0))
        cout<<a<<b<<c;
    if((k1!=0)&&(a==0))
        cout<<k1;
    if((k1==0)&&(a==0))
        cout<<"0";
    if(k1<0||a<0)
        cout<<")";
    cout<<" + ";
    if(k2<0||d<0)
        cout<<"(";
    if((k2!=0)&&(d!=0))
        cout<<k1<<" "<<abs(d)<<e<<f;
    if((k2==0)&&(d!=0))
        cout<<d<<e<<f;
    if((k2!=0)&&(d==0))
        cout<<k2;
    if((k2==0)&&(d==0))
        cout<<"0";
    if(k2<0||d<0)
        cout<<")";
    cout<<" = ";
    for(int i=1; i<=abs(m); i++)
    {
        if((n%i==0)&&(abs(m)%i==0))
            pos1=i;
    }
    if(l<0||m<0)
        cout<<"(";
    if((l!=0)&&(m!=0))
        cout<<l<<" "<<abs(m)/pos1<<e<<n/pos1;
    if((l==0)&&(m!=0))
        cout<<m/pos1<<e<<n/pos1;
    if((l!=0)&&(m==0))
        cout<<l;
    if((l==0)&&(m==0))
        cout<<"0";
    if(l<0||m<0)
        cout<<")";
    cout<<"\n";
    //减法部分
    if(k1<0||a<0)
        cout<<"(";
    if((k1!=0)&&(a!=0))
        cout<<k1<<" "<<abs(a)<<b<<c;
    if((k1==0)&&(a!=0))
        cout<<a<<b<<c;
    if((k1!=0)&&(a==0))
        cout<<k1;
    if((k1==0)&&(a==0))
        cout<<"0";
    if(k1<0||a<0)
        cout<<")";
    cout<<" - ";
    if(k2<0||d<0)
        cout<<"(";
    if((k2!=0)&&(d!=0))
        cout<<k1<<" "<<abs(d)<<e<<f;
    if((k2==0)&&(d!=0))
        cout<<d<<e<<f;
    if((k2!=0)&&(d==0))
        cout<<k2;
    if((k2==0)&&(d==0))
        cout<<"0";
    if(k2<0||b<0)
        cout<<")";
    cout<<" = ";
    for(int i=1; i<=abs(y); i++)
    {
        if((n%i==0)&&(abs(y)%i==0))
            pos2=i;
    }
    if(x<0||y<0)
        cout<<"(";
    if((x!=0)&&(y!=0))
        cout<<x<<" "<<abs(y)/pos2<<e<<n/pos2;
    if((x==0)&&(y!=0))
        cout<<y/pos2<<e<<n/pos2;
    if((x!=0)&&(y==0))
        cout<<x;
    if((x==0)&&(y==0))
        cout<<"0";
    if(x<0||y<0)
        cout<<")";
    cout<<"\n";
//乘法部分
    if(k1<0||a<0)
        cout<<"(";
    if((k1!=0)&&(a!=0))
        cout<<k1<<" "<<abs(a)<<b<<c;
    if((k1==0)&&(a!=0))
        cout<<a<<b<<c;
    if((k1!=0)&&(a==0))
        cout<<k1;
    if((k1==0)&&(a==0))
        cout<<"0";
    if(k1<0||a<0)
        cout<<")";
    cout<<" * ";
    if(k2<0||d<0)
        cout<<"(";
    if((k2!=0)&&(d!=0))
        cout<<k1<<" "<<abs(d)<<e<<f;
    if((k2==0)&&(d!=0))
        cout<<d<<e<<f;
    if((k2!=0)&&(d==0))
        cout<<k2;
    if((k2==0)&&(d==0))
        cout<<"0";
    if(k2<0||d<0)
        cout<<")";
    cout<<" = ";
    for(int i=1; i<=abs(f1); i++)
    {
        if((n1%i==0)&&(abs(f1)%i==0))
            pos3=i;
    }
    if(d1<0||f1<0)
        cout<<"(";
    if((d1!=0)&&(f1!=0))
        cout<<d1<<" "<<abs(f1)/pos3<<e<<n1/pos3;
    if((d1==0)&&(f1!=0))
        cout<<f1/pos2<<e<<n1/pos3;
    if((d1!=0)&&(f1==0))
        cout<<d1;
    if((d1==0)&&(f1==0))
        cout<<"0";
    if(d1<0||f1<0)
        cout<<")";
    cout<<"\n";
//除法部分
    if(k1<0||a<0)
        cout<<"(";
    if((k1!=0)&&(a!=0))
        cout<<k1<<" "<<abs(a)<<b<<c;
    if((k1==0)&&(a!=0))
        cout<<a<<b<<c;
    if((k1!=0)&&(a==0))
        cout<<k1;
    if((k1==0)&&(a==0))
        cout<<"0";
    if(k1<0||a<0)
        cout<<")";
    cout<<" / ";
    if(k2<0||d<0)
        cout<<"(";
    if((k2!=0)&&(d!=0))
        cout<<k1<<" "<<abs(d)<<e<<f;
    if((k2==0)&&(d!=0))
        cout<<d<<e<<f;
    if((k2!=0)&&(d==0))
        cout<<k2;
    if((k2==0)&&(d==0))
        cout<<"0";
    if(k2<0||d<0)
        cout<<")";
    cout<<" = ";
    if(n2!=0)
    {
        for(int i=1; i<=abs(f2); i++)
        {
            if((n2%i==0)&&(abs(f2)%i==0))
                pos4=i;
        }
        if(d2<0||f2<0||n2<0)
            cout<<"(";
        if((d2!=0)&&(f2!=0))
            cout<<d2<<" "<<abs(f2)/pos4<<e<<n2/pos4;
        if((d2==0)&&(f2!=0))
            cout<<f2/pos4<<e<<n2/pos4;
        if((d2!=0)&&(f2==0))
            cout<<d2;
        if((d2==0)&&(f2==0))
            cout<<"0";
        if(d2<0||f2<0)
            cout<<")";
    }
    else
        cout<<"Inf";
}

在这里插入图片描述

B1036

#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");
    printf("\n");
    for(int m=0;m<round(n/2)-2;m++)
    {
        for(int i=0;i<n;i++)
    {
        if(i==0||i==n-1)
        printf("%c",c);
        else
            printf(" ");
    }
     printf("\n");
      printf("\n");
    }
    for(int i=0;i<n;i++)
    {
        printf("%c",c);
    }
}

在这里插入图片描述

B1037

#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);
}

在这里插入图片描述

B1038

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
bool cmp(int a,int b)
{
    if(a<b)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,k,m;
    cin>>n;
    vector <int> ve1;
    vector <int> ve2;
    vector <int> ve3;
    map<int,int> mp;
    for(int i=0; i<n; i++)
    {
        cin>>m;
        ve1.push_back(m);
        ve3.push_back(m);
    }
    cin>>k;
    for(int i=0; i<k; i++)
    {
        cin>>m;
        ve2.push_back(m);
    }
    sort(ve1.begin(),ve1.end(),cmp);
    sort(ve3.begin(),ve3.end(),cmp);
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0; i<ve1.size(); i++)
        for(int x=0; x<ve3.size(); x++)
        {
            if(ve1[i]==ve3[x])
                mp[ve1[i]]+=1;
        }
    cout<<mp[ve2[0]];
    for(int i=1; i<k; i++)
    {
        cout<<" "<<mp[ve2[i]];
    }
}

在这里插入图片描述

B1039

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
    string str1,str2;
    int sum1=0,sum2=0,mini,sum3;
    cin>>str1>>str2;
    vector <char> ve1;
    vector <char> ve2;
    vector <char> ve3;
    vector <char> ve4;
    map<char,int> mp1;
    map<char,int> mp2;
    for(int i=0; i<str1.length(); i++)
    {
        ve1.push_back(str1[i]);
        ve3.push_back(str1[i]);
    }
    for(int i=0; i<str2.length(); i++)
    {
        ve2.push_back(str2[i]);
        ve4.push_back(str2[i]);
    }
    sum3=str1.length();
    sort(ve1.begin(),ve1.end());
    auto end_unique1 = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique1, ve1.end());
    sort(ve2.begin(),ve2.end());
    auto end_unique2 = unique(ve2.begin(), ve2.end());
    ve2.erase(end_unique2, ve2.end());
    for(int i=0; i<ve1.size(); i++)
        for(int x=0; x<ve3.size(); x++)
        {
            if(ve1[i]==ve3[x])
                mp1[ve1[i]]+=1;
        }
    for(int i=0; i<ve2.size(); i++)
        for(int x=0; x<ve4.size(); x++)
        {
            if(ve2[i]==ve4[x])
                mp2[ve2[i]]+=1;
        }
    mini=min(ve1.size(),ve2.size());
    for(int i=0; i<mini; i++)
    {
        if(mp1[ve2[i]]>=mp2[ve2[i]])
        {
            sum3-=mp1[ve2[i]];
            sum1+=mp1[ve2[i]]-mp2[ve2[i]];
        }
        else
        {
            sum2+=mp2[ve2[i]]-mp1[ve2[i]];
        }
    }
    if(sum2>0)
        cout<<"No "<<sum2;
    else
    {
        if(sum1>0)
            cout<<"Yes "<<sum1+sum3;//还要加上缺少的
    }
}

在这里插入图片描述

B1040

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int sum=0;
    vector <int> ve1;
    vector <int> ve2;
    vector <int> ve3;
    for(int i=0;i<str.length();i++)
    {
        if(str[i]=='P')
        ve1.push_back(i);
        if(str[i]=='A')
        ve2.push_back(i);
        if(str[i]=='T')
        ve3.push_back(i);
    }
    for(int i=0;i<ve1.size();i++)
    {
        for(int x=0;x<ve2.size();x++)
        {
            if(ve2[x]>ve1[i])
            {
                for(int y=0;y<ve3.size();y++)
                {
                    if(ve3[y]>ve2[x])
                        sum+=1;
                }
            }
        }
    }
   cout<<sum%1000000007;
}

在这里插入图片描述

B1041

#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;
          }
      }
}

在这里插入图片描述

B1042

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
bool cmp(char a,char b)
{
    if(a>b)
        return true;
    else
        return false;
}
using namespace std;//必须在声明字符串前使用
int main()
{
string st;
int maxnum=0;
char maxc;
getline(cin,st);
vector <char> ve1;
vector <char> ve3;
map <char,int> mp;
    transform(st.begin(),st.end(),st.begin(),::tolower);
for(int i=0;i<st.size();i++)
{
    ve1.push_back(st[i]);
    ve3.push_back(st[i]);
}
    sort(ve1.begin(),ve1.end(),cmp);
    sort(ve3.begin(),ve3.end(),cmp);
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0; i<ve1.size(); i++)
        for(int x=0; x<ve3.size(); x++)
        {
            if(ve1[i]==ve3[x])
                mp[ve1[i]]+=1;
        }
        for(int i=0; i<ve1.size(); i++)
        {
            if(((mp[ve1[i]])>=maxnum)&&(ve1[i]>=97)&&(ve1[i]<=122))
        {
            maxnum=mp[ve1[i]];
            maxc=ve1[i];
        }
    }
    cout<<maxc<<" "<<maxnum;
}

在这里插入图片描述

B1043

#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++)
    {
        if(str[i]=='P')
            mp['P']+=1;
        if(str[i]=='A')
            mp['A']+=1;
        if(str[i]=='T')
            mp['T']+=1;
        if(str[i]=='e')
            mp['e']+=1;
        if(str[i]=='s')
            mp['s']+=1;
        if(str[i]=='t')
            mp['t']+=1;
    }
    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';
            mp['P']-=1;
        }
        if(mp['A']!=0)
        {
            cout<<'A';
            mp['A']-=1;
        }
        if(mp['T']!=0)
        {
            cout<<'T';
            mp['T']-=1;
        }
        if(mp['e']!=0)
        {
            cout<<'e';
            mp['e']-=1;
        }
        if(mp['s']!=0)
        {
            cout<<'s';
            mp['s']-=1;
        }
        if(mp['t']!=0)
        {
            cout<<'t';
            mp['t']-=1;
        }
    }
}

在这里插入图片描述

B1044

#include <iostream>
#include <map>
#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]>=48&&ve[i][0]<=57)
        {
            int ot = stoi(ve[i],0,10);
            if((ot/13)>0)
                cout<<b[(ot/13)-1]<<" ";
            cout<<a[ot%13]<<endl;
        }
        else
        {
            if(ve[i].length()>3)
            {
                str1=ve[i].substr(0,3);
                for(int m=0; m<12; m++)
                {
                    if(b[m]==str1)
                        pos1=m;
                }
                str2=ve[i].substr(4,3);
                for(int n=0; n<12; 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<12; k++)
                {
                    if(a[k]==ve[i])
                        cout<<k<<endl;
                }
            }
        }
    }
}

在这里插入图片描述

B1045

#include <iostream>
#include <vector>
#include <algorithm>
bool cmp(int a,int b)
{
    if(a<b)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
int n,m;
cin>>n;
vector <int> ve1;
vector <int> ve2;
for(int i=0;i<n;i++)
{
    cin>>m;
    ve1.push_back(m);
}
for(int i=1;i<ve1.size();i++)
{
    if(i+1<ve1.size())
    {
       if((ve1[i]>=ve1[i-1])&&(ve1[i+1]>=ve1[i]))
        ve2.push_back(ve1[i]);
    }
}
if(ve1[0]<ve1[1])
    ve2.push_back(ve1[0]);
if(ve1[n-1]>ve1[n-2])
    ve2.push_back(ve1[n-1]);
sort(ve2.begin(),ve2.end(),cmp);
cout<<ve2.size()<<endl;
cout<<ve2[0];
for(int i=1;i<ve2.size();i++)
    cout<<" "<<ve2[i];
}

在这里插入图片描述

B1046

#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;
}

在这里插入图片描述

B1047

#include <iostream>//跟32题几乎一模一样
#include <map>
#include <vector>
#include <algorithm>
struct compete
{
    int id;
    int memid;
    int grade;

} a[10000];
bool cmp(compete a,compete b)
{
    if(a.id<b.id)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,m=0,maxgrade=0,maxid=0;
    char c;
    cin>>n;
    //利用vector进行对编号的排序
    //再开一个vector去重,利用map来进行计数
    vector<compete>ve;
    vector<int>ve1;
    map<int,int> mp;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].id>>c>>a[i].memid>>a[i].grade;
        ve.push_back(a[i]);
        ve1.push_back(a[i].id);
    }
    sort(ve.begin(),ve.end(),cmp);
    sort(ve1.begin(), ve1.end());
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0; i<ve1.size(); i++)
    {
        while(m<ve.size())
        {
            if(ve1[i]==ve[m].id)
            {
                mp[ve1[i]]+=ve[m].grade;
                m+=1;
            }
            else
                break;
        }
    }
    for(int i=0; i<mp.size(); i++)
    {
        if(mp[i]>maxgrade)
        {
            maxgrade=mp[i];
            maxid=i;
        }
    }
    cout<<maxid<<" "<<maxgrade;
}

在这里插入图片描述

B1048

#include <iostream>
  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,pos2;
    m=str1.length();
    n=str2.length();
      for(int i=0;i<str1.length();i++)
      {
          if((i+1)%2==1)
            {
                pos1=(str1[m-1]+str2[n-1]-'0'-'0')%13;
                str2[n-1]=a[pos1];
            }
          else
          {
              pos2=str2[n-1]-str1[m-1];
              if(pos2<0)
                 pos2+=10;
                str2[n-1]=a[pos2];
          }
          m-=1;
          n-=1;
      }
      for(int i=0;i<str2.length();i++)
        cout<<str2[i];
  }

在这里插入图片描述

B1049

#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main()
{
    int n;
    double a,m,sum=0;
    cin>>n;
    vector<double> ve;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        ve.push_back(m);
    }
    for(int i=0;i<n;i++)
    {
        a=0;
        for(int x=i;x<n;x++)
        {
            a+=ve[x];
            sum+=a;
        }
    }
    cout<<fixed<<setprecision(2)<<sum;
}

在这里插入图片描述

B1051

#include <iostream>
#include <math.h>
#include <iomanip>
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)-sin(p1)*sin(p2));
 b=r1*r2*(cos(p2)*sin(p1)+sin(p2)*cos(p1));
 cout<<fixed<<setprecision(2)<<a;
 cout<<fixed<<setprecision(2)<<b<<"i";
}

在这里插入图片描述

B1054

#include <iostream>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;
bool isnum(string s)
{
    stringstream sin(s);
    double t;
    char p;
    if(!(sin >> t))
        return false;
    if(sin >> p)
        return false;
    else
        return true;
}
int main()
{
    int n,pos;
    double c,sum1=0,sum2=0;
    cin>>n;
    string str;
    vector<string>ve;
    for(int i=0; i<n; i++)
    {
        cin>>str;
        ve.push_back(str);
    }

    for(int i=0; i<n; i++)
    {
        if(isnum(ve[i]))
        {
            c=stod(ve[i]);
               if((c>=(-1000))&&(c<=1000))
               {
                   if(ve[i].find('.')==true)
                   {
                       cout<<"Z";
                       pos=ve[i].length()-ve[i].find('.')-1;
                       if(pos>2)
                        cout << "ERROR:" << ve[i] << " is not a legal number." << endl;
                       else
                        {
                            sum1+=c;
                            sum2+=1;
                        }
                   }
                    else
                    {
                            sum1+=c;
                            sum2+=1;
                    }
               }

              else
              cout << "ERROR:" << ve[i] << " is not a legal number." << endl;
        }

        else
            cout << "ERROR:" << ve[i] << " is not a legal number." << endl;
    }
    if(sum2==0)
      cout<<"The average of 0 numbers is Undefined";
    if(sum2>0)
    cout<<"The average of "<<sum2<<" numbers is "<<fixed<<setprecision(2)<<sum1/sum2;
}

在这里插入图片描述

B1056

#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);
}

在这里插入图片描述

B1057

#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;
}

在这里插入图片描述

B1059

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool isPrime(int number)
{
    for(int i=2; i*i<=number; i++)
        if (number%i==0)
            return false;
    return true;
}
bool exist(string str,vector<string>& ve1,int n)
{
    for(int i=0; i<n; i++)
    {
        if(str==ve1[i])
            return true;
    }
    return false;
}
int main()
{
    int n,num;
    cin>>n;
    string str1,str2;
    vector <string> ve1;
    vector <string> ve2;
    map<string,int> mp;
    map<string,int> mp1;
    for(int i=0; i<n; i++)
    {
        cin>>str1;
        ve1.push_back(str1);
        mp1[str1]=i+1;
    }
    int k;
    cin>>k;
    for(int i=0; i<k; i++)
    {
        cin>>str2;
        ve2.push_back(str2);
    }
    for(int i=0; i<k; i++)
    {
        cout<<ve2[i]<<":";
        bool a=exist(ve2[i],ve1,n);
        //首先是判断是否有这个字符串
        //如果有那么往下进行判断
        //1.判断是否已经输出过 1.1输出过则不用往下走 1.2未输出
        //2.未输出判断此时要转换为整形
        //2.1判断是否为1 2.2判断是否为素数 2.3不同于前两者
        if(a==false)
            cout<<"Are you kidding?"<<endl;
        else
        {
            if(mp[ve2[i]]>0)
                cout<<"Checked"<<endl;
            else
            {
                if(mp1[ve2[i]]==1)
                {
                    cout<<"Mystery Award"<<endl;
                    mp[ve2[i]]+=1;
                }
                else if(isPrime(mp1[ve2[i]])==true)
                {
                    cout<<"Minion"<<endl;
                    mp[ve2[i]]+=1;
                }
                else
                {
                    cout<<"Chocolate"<<endl;
                    mp[ve2[i]]+=1;
                }
            }
        }
    }
}

在这里插入图片描述

B1060

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n,m,sum;
    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=0;
        for(int x=0; x<n; x++)
        {
            if(ve[x]>i)
                sum+=1;
        }
        if(sum==i)
                cout<<i;
    }
}

在这里插入图片描述

B1061

#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;
}

在这里插入图片描述

B1062

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n1,n2,k,pos;
    char a,b;
    double m1,m2;
    //先找到在范围内的数字存入vector然后再进行检测是否可以被约分
    double c,d;//分数结果
    int e;//确定大概范围
    vector <int> ve;
    vector <int> ve1;
    cin>>n1>>a>>m1>>n2>>b>>m2>>k;
    c=n1/m1;
    d=n2/m2;
    e=int(d*k);
    for(double i=0;i<k;i++)
    {
        if(((i/12)>c)&&(d>(i/12)))
            ve.push_back(i);
    }
    for(int i=0;i<ve.size();i++)
    {
        pos=1;
        for(int k=2;k<12;k++)
        {
            if((ve[i]%k==0)&&(12%k==0))
                  pos=k;
        }
        if(pos==1)
            ve1.push_back(ve[i]);
    }
    cout<<ve1[0]<<"/"<<k;
    for(int i=1;i<ve1.size();i++)
        cout<<" "<<ve1[i]<<"/"<<k;
}

在这里插入图片描述

B1063

#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];
}

在这里插入图片描述

B1064

#include <iostream>
#include <vector>
#include <algorithm>
bool cmp(int a,int b)
{
    if(a<b)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,sum;
    string str;
    cin>>n;
    vector <int> ve;
    for(int i=0;i<n;i++)
        {
            sum=0;
            cin>>str;
            for(int m=0;m<str.length();m++)
            {
                sum+=str[m]-'0';
            }
ve.push_back(sum);
        }
    sort(ve.begin(),ve.end(),cmp);
    auto end_unique = unique(ve.begin(), ve.end());
    ve.erase(end_unique, ve.end());
    cout<<ve.size()<<endl;
    for(int i=0; i<ve.size(); i++)
        if(i==0)
        cout<<ve[i];
    else
        cout<<" "<<ve[i];
}

在这里插入图片描述

B1065

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
bool cmp(int a,int b)
{
    if(a<b)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,m,k,h,sum;
    cin>>n;
    int x,y;
    map<int,int> mp;
    vector <int> ve;
    vector <int> ve1;
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        mp[x]=y;
        mp[y]=x;
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        ve1.push_back(x);
    }
    for(int i=0; i<m; i++)
    {
        sum=0;
        for(int k=0; k<m; k++)
        {
            if(mp[ve1[i]]!=ve1[k])
                sum+=1;
        }
        if(sum==ve1.size())
            ve.push_back(ve1[i]);
    }
    sort(ve.begin(),ve.end(),cmp);
    cout<<ve.size()<<endl;
    for(int i=0; i<ve.size(); i++)
    {
        if(i==0)
            cout<<ve[i];
        else
            cout<<" "<<ve[i];
    }
}

在这里插入图片描述

B1066

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
    int m,n,a,b,c;
    int h;
    string str;
    vector <int> ve;
    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(0);
            else
                ve.push_back(h);
        }

    }
    for(int i=0; i<ve.size(); i++)
    {
        if((i+1)%5==1)
        {
            if(ve[i]<10)
                cout<<"00";
            if(ve[i]<=99&&ve[i]>=10)
                cout<<"0";
            cout<<ve[i];
        }
        else if((i+1)%5==0)
        {
            cout<<" ";
            {
                if(ve[i]<10)
                    cout<<"00";
                if(ve[i]<=99&&ve[i]>=10)
                    cout<<"0";
                cout<<ve[i]<<endl;
            }
        }
        else
        {
            cout<<" ";
            {
                if(ve[i]<10)
                    cout<<"00";
                if(ve[i]<=99&&ve[i]>=10)
                    cout<<"0";
                cout<<ve[i];
            }
        }
    }
}

在这里插入图片描述

B1067

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    string str1,str2;
    int n,sum=0,pos;
    cin>>str1>>n;
    vector <string> ve;
    for(int i=0;; i++)
    {
        cin>>str2;
        if(str2!="#")
            ve.push_back(str2);
        else
            break;
    }
    for(int i=0; i<ve.size(); i++)
    {
        sum+=1;
        if(ve[i]==str1)
        {
            pos=i;
            break;
        }
        if(sum>3)
            break;
    }
    if(sum<=3)
    {
        for(int i=0; i<sum-1; i++)
            cout<<"Wrong password:"<<ve[i]<<endl;
        cout<<"Welcome in"<<endl;
    }
    else
    {
        for(int i=0; i<3; i++)
            cout<<"Wrong password:"<<ve[i]<<endl;
        cout<<"Account locked";
    }
}

在这里插入图片描述

B1068

#include <iostream>
#include <vector>
#include <math.h>
//我觉得第一个答案有问题
using namespace std;
int main()
{
    int m,n,tol,temp;
    cin>>m>>n>>tol;
    vector<vector<int>> ve;
    vector<int> ve1;
    vector<int> v;
    for (int i = 0; i <n; i++)//输入r*c的二维数组
	{
		v.clear();//子数组返回时要清除
		for (int j = 0; j <m; j++)
		{
			cin >> temp;
			v.push_back(temp);
		}
		ve.push_back(v);
	}
    for(int x=0;x<n;x++)
    {
        for(int y=0;y<m;y++)
        {
            if((x-1>=0)&&(x+1<=n-1)&&(y-1>=0)&&(y+1<=m-1))
            {
                if((fabs(ve[x][y]-ve[x-1][y-1])>tol)&&(fabs(ve[x][y]-ve[x-1][y])>tol)&&(fabs(ve[x][y]-ve[x-1][y+1])>tol)&&(fabs(ve[x][y]-ve[x][y-1])>tol)&&(fabs(ve[x][y]-ve[x][y+1])>tol)&&(fabs(ve[x][y]-ve[x+1][y-1])>tol)&&(fabs(ve[x][y]-ve[x+1][y])>tol)&&(fabs(ve[x][y]-ve[x+1][y+1])>tol))
                  {
                      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";
}

B1069

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int m,n,s,a;
    cin>>m>>n>>s;
    string str;
    vector<string> ve;
    vector<string> ve1;
    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)
        {
            ve1.push_back(ve[i]);
            a=ve1.size();
            auto end_unique = unique(ve1.begin(), ve1.end());
            ve1.erase(end_unique, ve1.end());
            while(ve1.size()<a)
            {
                i++;
                ve1.push_back(ve[i]);
                a=ve1.size();
                auto end_unique = unique(ve1.begin(), ve1.end());
                ve1.erase(end_unique, ve1.end());
            }
        }
    }
    for(int i=0; i<ve1.size(); i++)
        cout<<ve1[i]<<endl;
}

在这里插入图片描述

B1070

#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<<round(sum);
}

在这里插入图片描述

B1071

#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;
    }
}

在这里插入图片描述

B1072

#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();
}

在这里插入图片描述

B1074

#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
   string n1,n2,n3;
   int maxi,pos;
   int x,y=0,m,n;
   cin>>n1>>n2>>n3;
   vector<int> ve1;
   vector<int> ve2;
   int a=n1.length();
   int b=n2.length();
   int c=n3.length();
   maxi=max(b,c);
   for(int i=b;i<maxi;i++)
        n2="0"+n2;
    for(int i=c;i<maxi;i++)
        n3="0"+n3;
    b=n2.length();
    c=n3.length();
   for(int i=0;i<maxi;i++)
   {
       m=(n2[b-1]+n3[c-1]+y-'0'-'0');
       n=(n1[a-1]-'0');
       if(n==0)
        n=10;
       x=m%n;
       y=m/n;
       a--;
       b--;
       c--;
       ve1.push_back(x);
   }
   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];
   }
}

在这里插入图片描述

B1075

#include <iostream>
#include <vector>
using namespace std;
struct node
{
    string address;
    int data;
    string next;
} a[100000];
int main()
{
    int n,k,m;
    string beginad;
    cin>>beginad>>n>>k;
    vector<node> ve1;
    vector<node> ve2;
    vector<node> ve3;
    vector<node> ve4;
    vector<node> ve5;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].address>>a[i].data>>a[i].next;
    }

    for(int i=0; i<n; i++)
    {
        if(a[i].address==beginad)
        {
            beginad=a[i].next;
            ve5.push_back(a[i]);
            i=-1;//如果是0,每次开始就是1
        }
        if(ve5.size()==n)
            break;
    }
    for(int i=0; i<n; i++)
    {
        if(ve5[i].data<0)
            ve1.push_back(ve5[i]);
        else if(ve5[i].data>k)
            ve3.push_back(ve5[i]);
        else
            ve2.push_back(ve5[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<n;i++)
    {
        cout<<ve4[i].address<<" "<<ve4[i].data<<" ";
        if(i!=n-1)
        cout<<ve4[i+1].address<<endl;
        else
        cout<<-1<<endl;
    }
}

在这里插入图片描述

B1076

#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];
}

在这里插入图片描述

B1077

#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;
}

在这里插入图片描述

B1080

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
struct grade
{
    string str;
    int p;
    int m;
    int f;
    double g;
}a[10000];
bool cmp(grade a,grade b)
{
    if(a.g>b.g)
        return true;
    else if(a.g==b.g)
    {
        if(a.str<b.str)
            return true;
        else
            return false;
    }
    else
        return false;
}
int main()
{
    map<string,grade> mp;
    int P,M,N,sum=0;
    string str,str1;
    cin>>P>>M>>N;
    vector <string> ve;
    vector <grade> ve1;
    for(int i=0; i<P; i++)
    {
        cin>>str;
        str1=str;//不这样写 每次的str残留的是上次的
        cin>>mp[str1].p;
        ve.push_back(str);
    }
    for(int i=0; i<M; i++)
    {
        cin>>str;
        str1=str;//不这样写 每次的str残留的是上次的
        cin>>mp[str1].m;
        ve.push_back(str);
    }
    for(int i=0; i<N; i++)
    {
        cin>>str;
        str1=str;//不这样写 每次的str残留的是上次的
        cin>>mp[str1].f;
        ve.push_back(str);
    }
    for(int i=0; i<ve.size(); i++)
    {
        if(mp[ve[i]].m>mp[ve[i]].f)
            mp[ve[i]].g=mp[ve[i]].m*0.4+mp[ve[i]].f*0.6;
        else
            mp[ve[i]].g=mp[ve[i]].f;
    }
    sort(ve.begin(), ve.end());
    auto end_unique = unique(ve.begin(), ve.end());
    ve.erase(end_unique, ve.end());
    for(int i=0; i<ve.size(); i++)
    {

        if(mp[ve[i]].p>=200&&mp[ve[i]].g>=60)
            {

                a[sum].str=ve[i];
        if(mp[ve[i]].p==0)
            a[sum].p=-1;
        else
            a[sum].p=mp[ve[i]].p;
        if(mp[ve[i]].m==0)
            a[sum].m=-1;
        else
            a[sum].m=mp[ve[i]].m;
        if(mp[ve[i]].f==0)
            a[sum].f=-1;
        else
            a[sum].f=mp[ve[i]].f;
        a[sum].g=round(mp[ve[i]].g);
        sum++;
        }
    }
 for(int i=0;i<sum;i++)
    ve1.push_back(a[i]);
 sort(ve1.begin(),ve1.end(),cmp);
 for(int i=0;i<ve1.size();i++)
    cout<<ve1[i].str<<" "<<ve1[i].p<<" "<<ve1[i].m<<" "<<ve1[i].f<<" "<<ve1[i].g<<endl;
}

在这里插入图片描述

B1081

#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;
            }
        }
    }
}

在这里插入图片描述

B1082

#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;
    }
}

在这里插入图片描述

B1083

#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
bool cmp1(int a,int b)
{
    if(a<b)
        return true;
    else
        return false;
}
struct number
{
    int cha;
    int ci;
} b[5000];
bool cmp2(number a,number b)
{
    if(a.cha>b.cha)
        return true;
    else
        return false;
}
using namespace std;
int main()
{
    int n,a,k;
    cin>>n;
    vector<int>ve;
    vector<int>ve1;
    vector<int>ve3;
    vector<number> ve4;
    map<int,int> mp;
    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);
        if(k>0)
        {
            ve1.push_back(k);
            ve3.push_back(k);
        }
    }
    sort(ve1.begin(),ve1.end(),cmp1);
    sort(ve3.begin(),ve3.end(),cmp1);
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0; i<ve1.size(); i++)
    {
        for(int x=0; x<ve3.size(); x++)
        {
            if(ve1[i]==ve3[x])
            {
                mp[ve1[i]]+=1;
            }
        }
        if(mp[ve1[i]]>1)
        {
            b[i].cha=ve1[i];
            b[i].ci=mp[ve1[i]];
            ve4.push_back(b[i]);
        }
    }
    sort(ve4.begin(),ve4.end(),cmp2);
    for(int i=0; i<ve4.size(); i++)
        cout<<ve4[i].cha<<" "<<ve4[i].ci<<endl;
}

在这里插入图片描述

B1085

#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
using namespace std;
struct ph
{
    string id;
    int grade;
    string name;
} a[1000];
struct ph1
{
    int sumgrade;
    string name;
    int ren;
} b[1000];
bool cmp(ph1 a,ph1 b)
{
    if(a.sumgrade>b.sumgrade)
        return true;
    else if(a.sumgrade==b.sumgrade)
    {
        if(a.ren<b.ren)
            return true;
        else if(a.ren==b.ren)
        {
            if(a.name<b.name)
                return true;
            else
                return false;
        }
        else
            return false;
    }
    else
        return false;
}
int main()
{
    int n;
    cin>>n;
    vector<string> ve1;
    vector<ph1> ve2;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].id>>a[i].grade>>a[i].name;
        transform(a[i].name.begin(),a[i].name.end(),a[i].name.begin(),::tolower);
        if(a[i].id[0]=='T')
            a[i].grade=a[i].grade*1.5;
        if(a[i].id[0]=='B')
            a[i].grade=a[i].grade/1.5;
        ve1.push_back(a[i].name);
    }
sort(ve1.begin(),ve1.end());
    auto end_unique = unique(ve1.begin(), ve1.end());
    ve1.erase(end_unique, ve1.end());
    for(int i=0;i<ve1.size();i++)
        cout<<ve1[i]<<endl;
    for(int i=0; i<ve1.size(); i++)
    {
        for(int k=0; k<n; k++)
        {
            if(a[k].name==ve1[i])
            {
                b[i].sumgrade+=a[k].grade;
                b[i].name=ve1[i];
                b[i].ren++;
            }
        }
        ve2.push_back(b[i]);
    }
    sort(ve2.begin(),ve2.end(),cmp);
    cout<<ve2.size()<<endl;
    for(int i=0;i<ve2.size();i++)
        {if(ve2[i-1].sumgrade==ve2[i].sumgrade)
        cout<<i;
    else
        cout<<i+1;
        cout<<" "<<ve2[i].name<<" "<<ve2[i].sumgrade<<" "<<ve2[i].ren<<endl;}
}

在这里插入图片描述

B1086

#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());
     cout<<str;
}

在这里插入图片描述

B1087

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a;
    vector<int> ve;
    for(int i=0;i<n;i++)
    {
        a=(i/2)+(i/3)+(i/5);
        ve.push_back(a);
    }
    sort(ve.begin(),ve.end());
    auto end_unique = unique(ve.begin(), ve.end());
    ve.erase(end_unique, ve.end());
    cout<<ve.size();
}

在这里插入图片描述

B1088

#include <iostream>
#include <math.h>
#include <map>
using namespace std;
void gx(int a)
{
    if(a>0)
        cout<<"Gai";
    else if(a==0)
        cout<<"Ping";
    else
        cout<<"Cong";
}

int main()
{
    int a,b,c,x,y,m;
    int jia=0,yi,bin;
    cin>>m>>x>>y;
    map<int,string> mp;
    for(int a=1; a<10; a++)
    {
        for(int b=1; b<10; b++)
        {
            for(int c=1;c<100;c++)
            {
                if((fabs(9*a-9*b)==x*c)&&(c*y==(10*b+a)))
                {
                    if(jia<10*a+b)
                    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);
                  }
}

在这里插入图片描述

B1091

#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;
        }
}

在这里插入图片描述

B1092

#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];
}
}

在这里插入图片描述

B1094

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
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 l,k;
    int b;
    cin>>l>>k;
    string str,a;
    cin>>str;
    for(int i=0; i<l; i++)
    {
        if(i+k<l)
        {
          string a=str.substr(i,k);
        b=stoi(a);
        if(isPrime(b))
        {
           goto a;
        }
        }
    }
    cout<<"404";
    if(false)
a:
        cout<<b;
}

在这里插入图片描述

B1095

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct zkz
{
    string id;
    int grade;
} a[10000];
struct kc
{
    string id;
    int ren;
} b[1000];
bool cmp1(zkz a,zkz b)
{
    if(a.grade>b.grade)
        return true;
    else if(a.grade==b.grade)
    {
        if(a.id<b.id)
            return true;
        else
            return false;
    }
    else
        return false;
}
bool cmp2(kc a,kc b)
{
    if(a.ren>b.ren)
        return true;
    else if(a.ren==b.ren)
    {
        if(a.id<b.id)
            return true;
        else
            return false;
    }
    else
        return false;
}
int main()
{
    int n,m,sum=0,sum1=0;
    cin>>n>>m;
    vector<zkz> ve1;
    vector<string>ve2;
    vector<zkz> ve3;
    vector<string>ve4;
    vector<string>ve5;
    vector<kc>ve6;
    string str1,str2;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].id>>a[i].grade;
        ve1.push_back(a[i]);
    }
    for(int i=0; i<m; i++)
    {
        cin>>str1>>str2;
        ve2.push_back(str1);
        ve2.push_back(str2);
    }
    for(int i=0; i<ve2.size(); i+=2)
    {
        cout<<"Case "<<(i/2)+1<<":"<<ve2[i]<<" "<<ve2[i+1]<<endl;
        if(ve2[i]=="1")
        {
            for(int k=0; k<n; k++)
            {
                if(a[k].id.substr(0,1)==ve2[i+1])
                    ve3.push_back(a[k]);
            }
            sort(ve3.begin(),ve3.end(),cmp1);
            for(int h=0; h<ve3.size(); h++)
                cout<<ve3[h].id<<" "<<ve3[h].grade<<endl;
        }
        if(ve2[i]=="2")
        {
            sum=0;
            sum1=0;
            for(int k=0; k<n; k++)
            {
                if(a[k].id.substr(1,3)==ve2[i+1])
                {
                    sum+=a[k].grade;
                    sum1++;
                }
            }
            if(sum!=0)
                cout<<sum1<<" "<<sum<<endl;
            if(sum==0)
                cout<<"NA";
        }
        if(ve2[i]=="3")
        {
            for(int k=0; k<n; k++)
            {
                if(a[k].id.substr(4,6)==ve2[i+1])
                {
                    ve4.push_back(a[k].id.substr(1,3));
                    ve5.push_back(a[k].id.substr(1,3));
                }
            }
                sort(ve4.begin(), ve4.end());
                auto end_unique = unique(ve4.begin(), ve4.end());
                ve4.erase(end_unique, ve4.end());
               for(int h=0; h<ve4.size(); h++)
                {
                    b[h].id=ve4[h];
                    b[h].ren=count(ve5.begin(),ve5.end(),ve4[h]);
                    ve6.push_back(b[h]);
                }
                sort(ve6.begin(),ve6.end(),cmp2);
                for(int h=0; h<ve6.size(); h++)
                    cout<<ve6[h].id<<" "<<ve6[h].ren<<endl;
            }
        }
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值