训练1

来源:互联网 发布:本坦库尔fm数据 编辑:程序博客网 时间:2024/04/30 06:18

气球颜色

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char  color[1000][16];
int math[1000];
int main()
{ int i;
 while(scanf("%d",&i)!=EOF&&i!=0)
 {  memset(math,0,1000*sizeof(int));
   int flag1=i;
  for(int j=0;j<i;j++)
  {
   
   scanf("%s",&color[j]);
   for(int k=0;k<j;k++)
   {
    if(strcmp(color[k],color[j])==0&&j!=0)
      {
       math[k]=math[k]+1;
    //cout<<"a"<<math[k]<<endl;
       } }}
  int max=0;
  int flag=0;
   for(int j=0;j<flag1;j++)
  { if(math[j]>max)
      {
       max=math[j];
       flag=j;
     }  
          
  }
   /* for(int j=0;j<flag1;j++)
  { cout<<math[j]<<endl;
          
  }
  for(int j=0;j<i;j++)
  {   
  cout<<color[j]<<endl;    
  }*/
   
   cout<<color[flag]<<endl;
   
   
   
  }
  
  
  
  
 }

士兵队列

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char  color[1000][16];
int math[5008];
int main()
{
int z,k,m;
scanf("%d",&z);
while(z--)
{  
 scanf("%d",&k);
 int sum=k;
 if(sum<=3)
 {
   cout<<"1";
   for(int i=2;i<=sum;i++)
  cout<<" "<<i;
  cout<<endl;
  continue;
  
  }
 for(int i=1;i<=k;i++)
      {
       
       math[i]=i;
       
       
   }
   /* for(int i=1;i<=k;i++)
      {
       
      cout<<math[i];
       
       
   }*/
     while(1)
     {  //cout<<"456";
      
  int flag=0;
  for(int i=1;i<=k;i++)
  {
   if(math[i])
   flag++;
   if(flag==2)
   {
    math[i]=0;
    flag=0;
       sum--; 
    
   }
   
   
  }
  if(sum<=3)
      {
       
       
       break;
   }
  int flag1=0;
         for(int i=1;i<=k;i++)
  {
   if(math[i])
   flag1++;
   if(flag1==3)
   {
    math[i]=0;
    flag1=0;
    sum--;
    
   }
   
   
  }
  if(sum<=3)
      {
       
       
       break;
   }
      
      
      
      
      
  }
  //cout<<sum;
 
   cout<<"1";
   sum--;
   for(int i=2;sum>0;i++)
   {
    if(math[i])
    {
    cout<<" "<<math[i];
    sum--;}
    
   }
   cout<<endl;
 
 
}

}
反置
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char math[1001];
int main()
{
 int i;
 scanf("%d",&i);
 getchar();
 while(i--)
 { 
   //memset(math,'1', sizeof(math));
    gets(math);
    //getchar();
    //cout<<math<<endl;
     int x=strlen(math);
    // cout<<x<<endl;
     int flag=0;
     int flag1=-1;
     int sum=-1;
       for(int i=0;i<=x;i++)
       { 
        if((math[i]==' ')&&(i!=x))
        {  
     flag1=i;
           
     sum=i-flag;
     flag=i+1;
            int j=i;
         for( int k=sum;k>0;k--)
         {
          j--;
        
          printf("%c",math[j]);
         
    }
         
            
         
     }
    if(math[i]==' ')
     { printf(" ");
     }
     //cout<<"sssssssss"<<flag1;
      if(i==x)
        {   sum=i-flag;
      
            int j=i;
         for( int k=sum;k>0;k--)
         {
          j--;
         printf("%c",math[j]);
          }
         
     }
    
         
   
    }
 
  
     
 
  
   printf("\n");
  
  
  
 }
 
 
 
 
 return 0;
}
数字分割
#include<queue>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<functional>
#include <cstdlib>
#include<string.h>
//0051231232050775
char a[1000000000];
using namespace std;
typedef long long int  LL;
int main()
{ long long int flag=0,x=0,ze;
priority_queue<LL,vector<LL>,greater<LL> >p1;
while(scanf("%s",a)!=EOF)
{
flag=0;x=0;
for(int i=0;a[i]!='\0';i++)
{   if(a[i]==0&&flag==0)
    {
   
      flag=1;
      continue;
   
 }
  if(a[i]=='5'&&i==0)
  {
   continue;
  }
 if(a[i]=='5'&&i!=0)
 {
    if(a[i]=='5'&&a[i-1]=='5')
    {  continue;
    }
    else
    {p1.push(x);
  x=0;//cout<<x<<endl;
  continue;
    }
 
 }
 
 ze=a[i]-'0';
 x=x*10+ze;
 
 //cout<<x<<endl;
}
  if(x!=0)
  {
   p1.push(x);
  }



 ze=p1.top();
   cout<<ze;
   p1.pop();
  while(!p1.empty())
  { ze=p1.top();
   cout<<" "<<ze;
 p1.pop();
  }
 cout<<endl;


}

}

第几个数字
#include<queue>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<functional>
#include <cstdlib>
#include<string.h>
//0051231232050775
using namespace std;
typedef long long   LL;
int main()
{

 int x,y,za,zc;
 char c;
 while(cin>>x>>y)
 {  priority_queue<LL,vector<LL>,greater<LL> >p1;
  while(x--)
  {  cin>>c;
    if(c=='Q')
    { 
  
    za=p1.top();
    cout<<za<<endl;
    }
  
   else
    {cin>>zc;  
      p1.push(zc);
        if(p1.size()>y)
     {  p1.pop();
             
     }
     
     
     
  
     
     
    } 
   
   
   
   
   
   
   
  }
  
  
  
  
  
  
  
  
  
 }
 
 
 
 
 
 
 
 
 
 return 0;
 
}
数字转换
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char a[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char b[100000000];
char c[100000000];
int main()
{
 while(1)
{
 int x=-1,y=-1,flag=1,t1=0,t2=0;
 
 while(scanf("%s",b))
 { 
 // cout<<b<<x<<"  "<<y<<endl; 
 //three four + five six =
   
      if(b[0]=='=')
      { if(x==0&&y==0)
      break;
      else{
     cout<<x+y<<endl;
  break;
   }
      }
      
      if(b[0]=='+')
      {
       flag=0;
      // cout<<"rilegou"<<endl;
   }
      
  if(flag==1&&b[0]!='+')
  {
   
   
  for(int i=0;i<=9;i++)
  {
   if(strcmp(a[i],b)==0)
   {  if(t1==0)
    {x=i;
    t1++;}
     else
      x=x*10+i;
    
   // cout<<a[i]<<x<<"xxxx"<<endl;
   }
   
   
   
  }
   
   
   }
 if(flag!=1&&b[0]!='+')
 {
  
  
   
  for(int i=0;i<=9;i++)
  {
   if(strcmp(a[i],b)==0)
   {if(t2==0)
    {y=i;
    t2++;
    }
   else
    y=y*10+i; 
    
    //cout<<a[i]<<y<<"xxxx"<<endl;
   }
  
   
    //cout<<"rilegou"<<endl;
  }
  
  
 
  
 }
 
 
}
if(x==0&&y==0)
break;
   //cout<<x<<y<<endl;
 
  
   
  
  
 }  
  
 
 
return 0;
 
}