toj 部分题

//////2010
#include <iostream>
#include <map>
#include <cstring>
using namespace std;

map<int,int>m;
bool Prime[10007];
int P[10005],n;
const int maxn=10000;

int main()
{
    n=0;
    memset(Prime,1,sizeof(Prime));
    Prime[0]=Prime[1]=0;
    for(int i=2;i<=maxn;++i)    
    {
        if(Prime[i])
        {
            P[n++]=i;
            for(int j=2;j*i<=maxn;++j)
            {
                Prime[j*i]=0;
            }
        }
    }
    for(int i=0;P[i]!=0;i++)
        m[P[i]]=i;
    int n;
    while(cin>>n&&n)
    {
        int count=0;
        if(Prime[n]) count++;
        for(int i=2;i<=n;i++)
        {
            if(Prime[i]==0)
                continue;
            int sum=i;
            int j=P[m[i]+1];
            while(Prime[j]!=0&&sum<=n)
            {
                sum+=j;
                if(sum==n)
                {
                    count++;
                    break;
                }
                j=P[m[j]+1];
            }
        }
        cout<<count<<endl;
    }
    return 0;
}


/////3294
#include<stdio.h>
#include<iostream>
#include<string.h>
int num[333333];
int set[333333];
int under[333333];
int find(int x)
{
    int tmp;
    if (x!=set[x])
    {
        tmp = find(set[x]);
        under[x] += under[set[x]];
        set[x] = tmp;
    }
    return set[x];

}
void merge(int a,int b)
{
    int fx=find(a);
    int fy=find(b);
    if(fx!=fy)
    {
        under[fx]=num[fy];
        num[fy]+=num[fx];
        set[fx]=fy;
    }
}
int main()
{
    int n,a,b;
    char s[5];
    while(scanf("%d",&n)!=EOF)
    {
        memset(under,0,sizeof(under));
        for(int i=0; i<=n; i++)//初始化
        {
            set[i]=i;
            num[i]=1;
        }
        for(int i=0; i<n; i++)
        {
            scanf("%s",s);
            if(s[0]=='M')
            {
                scanf("%d%d",&a,&b);
                merge(a,b);
            }
            else
            {
                scanf("%d",&a);
                find(a);
                printf("%d\n",under[a]);
            }
        }
    }
    return 0;
} 
/*
6
M 1 6
C 1
M 2 4
M 2 6
C 3
C 4
*/


/////3484
#include<iostream>
#include<algorithm>
using namespace std;
int s[100000];
int main ()
{
    int y;
    cin>>y;
    while(y--)
    {
              int a;
              cin>>a;
              for(int i=0;i<a;i++)
              cin>>s[i];
              sort(s,s+a);
              int asd=0;
              for(int i=0;i<a-1;i++)
              {
                      asd+=s[i];
              }
              cout<<asd<<endl;
    }
    //system("pause");
    return 0;
}


////3579
#include<iostream>
 using namespace std;
 int pfac[6000];
 int qfac[6000];
 
 int ptable( int p )
 {
     int j = 0;
     
     for( int i = 1; i <= p; i++ )
         if( p % i == 0 )
             pfac[j++] = i;
             
     return j;
 }
 
 int qtable( int q )
 {
     int j = 0;
     
     for( int i = 1; i <= q; i++ )
         if( q % i == 0 )
             qfac[j++] = i;
     
     return j;
 }
 
 int main()
 {
     int p, q;
     cin >> p >> q; 
     
    int psize, qsize;
     psize = ptable(p);
     qsize = qtable(q);
     
     int i, j;
     for( i = 0; i < psize; i++ )
         for( j = 0; j < qsize; j++ )
             cout << pfac[i] << " " << qfac[j] << endl;
     
     return 0;
 } 

////////3861
#include<iostream>
using namespace std;
int main(){
    int n;
    while(cin>>n)
    {cout<<"Ann wins."<<endl;}
}

//////4088
#include <iostream>
#include<stdio.h>
#include<math.h> 
using namespace std;
bool isPrime(int num)
{
     if(num<=1)
     return 0;
     for (int i=2; i<=sqrt(num); i++)
     {
      if (num%i == 0)
      return false;
      }
      return true;
}
      int main()
{

    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        int counter = 0;
        for (int i=a; i<=b; i++)
        {
            if (isPrime(i))
            {
                counter++;
            }
        }
        if(isPrime(counter))
        {
            printf("YES");
            printf("\n");
        }
        else
        {
            printf("NO");
            printf("\n");
        }
    }
    //system("pause");
    return 0;
}

////////4116
#include<iostream>
using namespace std;
int cnm(int a,int b)
{
    if(a<b)
           swap(a,b);
           while(b)
           {
                   a=a%b;
                   swap(a,b);
           }
           return a;
}
int main()
{
    int a;
    cin>>a;
    while(a--)
    {
              int n,sum;
              cin>>n>>sum;
              for(int i=1;i<n;i++)
              {
                      int x;
                      cin>>x;
                      sum=cnm(sum,x);
              }
              cout<<sum<<endl;
    }
   // system("pause");
    return 0;
}


//////////3170
#include<iostream>
using namespace std;
int main ()
{
    int n,q,num,s[20000];
    while(cin>>n>>q)
    {
     int b=0;
         for(int j=1;j<=n;j++)
         {
                 int a;
                 cin>>a;
                 for(int i=b;i<b+a;i++)
                 s[i]=j;
                 b+=a;
         }
         for(int i=1;i<=q;i++)
         {       cin>>num;
                 cout<<s[num]<<endl;
         }       
     }
     //system("pause");
     return 0;
}          


///////1730
#include<iostream>
#include<cstring> 
using namespace std;
int main ()
{
    int s[20000]={0};
    for(int i=1;i<=10000;i++)
    {
            int a=i,b=i;
            while(b)
            {
                    a+=b%10;
                    b=b/10;
            }
            s[a]=1;
    }
    for(int i=1;i<=10000;i++)
    {
            if(s[i]==0)
            cout<<i<<endl;
    }
    //system("pause");
    return 0;
}


//////2218
#include<iostream>
using namespace std;
int cnm(int a,int b,int c)
{
    int sum=1,k=a;
    while(b)
    {
            if(b&1)
            sum=sum*k%c;
            k=k*k%c;
            b>>=1;
    }
    return sum;
}
int main()
{
    int a;
    while(cin>>a&&a!=0)
    {
     cout<<cnm(a%2006,a,2006)<<endl;
     }
     //system("pause");
     return 0;
}    


//////2218
#include<iostream>
using namespace std;
int cnm(int a,int b,int c)
{
    int sum=1,k=a;
    while(b)
    {
            if(b&1)
            sum=sum*k%c;
            k=k*k%c;
            b>>=1;
    }
    return sum;
}
int main()
{
    int a;
    while(cin>>a&&a!=0)
    {
     cout<<cnm(a%2006,a,2006)<<endl;
     }
     //system("pause");
     return 0;
}  


///////////2916
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int cnm(int a,int b)
{
    if(a<b)
    swap(a,b);
    while(b)
    {
            a=a%b;
            swap(a,b);
    }
    return a;
}
int main ()
{
    int x,y;
    while(cin>>x>>y)
    {
                    int n;
                    n=cnm(x,y);
                    cout<<y/n<<endl;
    }
    //system("pause");
    return 0;
}
//int cnm(int a,int b)
//{
    //if(a<b)
    //swap(a,b);
   // while(b)
    //{
     //       a=a%b;
      //      swap(a,b);
    //}
    //return a;
//}


//////4118
#include<iostream>
#include<cstring>
using namespace std;
 int main ()
 {
     int a[1000001];
     int n;
     while(cin>>n)
     {
                  int j=0;
                  memset(a,1,sizeof(a));
                  for(int i=n;i>0;i--)
                  {
                          if(a[i]&&i%2==0&&i>2)
                          a[(i-2)/2]=0;
                  }
                  for(int i=1;i<=n;i++)
                  
                          if(a[i])
                          j++;
                  
                  cout<<j<<endl;
     }
     //system("pause");
     return 0;
 }


////3855
#include<iostream>
#include<iomanip>
using namespace std;
int main ()
{
    int n,m;
    string menu[101];
    double price[101];
    while(cin>>n>>m)
    {
                    double z=0.0;
                    for(int i=0;i<n;i++)
                    cin>>menu[i]>>price[i];
                    for(int j=0;j<m;j++)
                    {
                            string d;
                            cin>>d;
                            for(int i=0;i<n;i++)
                            {
                                    if(d==menu[i])
                                    {
                                        z+=price[i];
                                        price[i]=0;
                                        break;
                                        }
                            }
                    }
                    cout<<fixed<<setprecision(2)<<z<<endl;
    }          
    //system("pause");
    return 0;
}


//////3161
#include<iostream>
using namespace std;
int main ()
{
    int m,n,a[1000];
    cin>>m>>n;
    for(int i=1;i<=m;i++)
    cin>>a[i];
    while(n--)
    {
              int sum=0;
              int x,y;
              cin>>x>>y;
              for(x;x<=y;x++)
              sum+=a[x];
              cout<<sum<<endl;
    }
    //system("pause");
    return 0;
}


/////////4102
#include<iostream>
#include<cmath>
using namespace std;
 int main ()
 {
     int u,n;
     cin>>u;
     while(u--)
     {
               cin>>n;
               for(int i=0;;i++)
               {
                       if(pow(2.0,i)>=n)
                       {cout<<i<<endl;break;}
               }
     }
     //system("pause");
     return 0;
 }

//////4101
#include <iostream>
using namespace std;
int main ()
{
    int u;
    cin>>u;
    while (u--)
    {
          int a=0,s=1,n;
              cin>>n;
              while (a<n)
              {
                    a+=s;
                    if (a<n)
                    s++;
              }
              cout<<s<<endl;
    }
   //system("pause");
    return 0;
}

////1192
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
    int u;
    cin>>u;
    int a[10000],s[10000];
    while (u)
    {
          int x=0,y=0;
          for (int i=1;i<=u;i++)
              cin>>a[i];
          for (int j=1;j<=u;j++)
              cin>>s[j];
          for (int i=1;i<=u;i++)
          {
              if (a[i]>s[i])
              {
                if (a[i]==2&&s[i]==1)
                y+=6;
                else if(a[i]-s[i]==1)
                y+=a[i]+s[i];
                else 
                x+=a[i];
                }
                else if (a[i]<s[i])
                {
                     if (a[i]==1&&s[i]==2)
                     x+=6;
                     else if (s[i]-a[i]==1)
                     x+=a[i]+s[i];
                     else 
                     y+=s[i];
                }
          }
             cout<<"A has "<<x<<" points. B has "<<y<<" points."<<endl;
             cin>>u;
             if (u!=0)
             cout<<endl;
    }
    //system ("pause");
    //return 0;
}

/////////4109
#include <iostream>
using namespace std;
int main ()
{
    int u;
    while (cin>>u&&u)
    {
          int a[u];
          int w=0,s=0;
          for (int i=0;i<u;i++)
          {
               cin>>a[i];
              if (a[i]%2!=0)
              w++;
              else 
              s++;
          }
          if (w>s&&u%2!=0)
          cout<<"Justice will prevail over evil."<<endl;
          else if(w<s&&u%2==0)
          cout<<"While the priest climbs a post, the devil climbs ten."<<endl;
          else 
          cout<<"I love this world."<<endl;
    }
    //system("pause");
    return 0;
}
          
/////////1680
#include <stdio.h>
int main()
{
 int n,m,num;
 scanf("%d",&n);
 while (n--)
 {
  scanf("%d",&m);
  if(m%2==0)
  {
   m/=2;
   num=m*(m-1);
  }
  else
  {
   num=(m/2)*(m/2-1)/2+(m/2+1)*(m/2)/2;
  }
  printf("%d\n",num);
 }
 return 0;
}

/////////3105
#include <iostream>
using namespace std;
int arr[100001];
int prime[100001];
int main(){
    for(int i=2;i<=100000;i++)
        arr[i]=1;
    for(int i=2;i<=100000;i++){
        if(arr[i]){
            for(int j=i+i;j<=100000;j+=i)
                arr[j]=0;
        }
    }
    for(int i=2,j=1;i<=100000;i++){
        if(arr[i]){
            prime[j]=i;
            j++;
        }
    }
    int n;cin>>n;
    while(n--){
        int m;
        cin>>m;
        cout<<prime[m]<<endl;
    }
}

///////2791
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        int l=s.length();
        if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u')
            cout<<s<<"cow"<<endl;
        else{
            for(int i=1;i<l;i++)
                cout<<s[i];
            cout<<s[0]<<"ow"<<endl;
        }
    }
}

////////3467
#include <iostream>
using namespace std;
int main(){
    int n;cin>>n;
    while(n--){
        long long a,sun=0;
        cin>>a;
        while(a){
            sun+=a%10;
            a/=10;
        }
        cout<<sun<<endl;
    }
}


///////////1457
#include<iostream>
using namespace std;
int main ()
{
    int u;
    cin>>u;
    while(u--)
    {
              int s,d;
              cin>>s>>d;
              if(s<d||(s+d)%2!=0)
              {
               cout<<"impossible"<<endl;
               }
               else
               cout<<(s+d)/2<<" "<<(s-d)/2<<endl;
    }
    return 0;
}


///////3914
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        int sun=0;
        while(n){
            sun+=n%2;
            n/=2;
        }
        cout<<pow(2,sun)<<endl;
    }
}


////////3982
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main ()
{
    int u;
    cin>>u;
    while (u--)
    {
          int t,y;
          cin>>t>>y;
          int a[y];
          for (int i=0;i<y;i++)
          {
              cin>>a[i];
          }
          sort(a,a+y);
          int s=0,d=0;
          for (int i=0;i<y;i++)
          {
              s+=a[i];
              if (t>=s)
              d++;
          }
          cout<<d<<endl;
    }
    return 0;
}

/////////3108
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int m1[10001],m2[10001],m3[10001],m4[10001],a,b,c=0;
        cin>>a>>b;
        for(int i=0;i<a;i++)
            cin>>m1[i];
        for(int i=0;i<b;i++)
            cin>>m2[i];
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if(m1[i]==m2[j]){
                    m3[c]=m1[i];
                    c++;
                    break;
                }
            }
        }
        sort(m3,m3+c);
        m4[0]=m3[0];
        int j=1;
        for(int i=1;i<c;i++){
            if(m3[i]!=m3[i-1]){
                m4[j]=m3[i];
                j++;
            }
        }
        for(int i=0;i<j-1;i++)
            cout<<m4[i]<<" ";
        cout<<m4[j-1]<<endl;
    }
}


/////////////2955
#include<iostream>
using namespace std;
int main ()
{
    int a[3],b[3];
    while (cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2])
    {
            int m,n;
       for(int i=0;i<=2;i++){
            int x=0,y=0;
            for(int j=0;j<=2;j++){
                if(a[i]!=a[j])
                    x++;
                if(b[i]!=b[j])
                    y++;
                                  }
            if(x==2)
                m=a[i];
            if(y==2)
                n=b[i];

                              }
                              cout<<m<<" "<<n<<endl;
      }
    return 0;
}           
         
///////3307
#include <iostream>
#include <algorithm>
using namespace std;
int m(int a,int b[],int r)
{
    for (int i=0;i<r;i++)
    
        if (a==b[i])
        return i+1;
    return -1;
    
}
int main ()
{
    int row ,t,s[120],d[120];
    while (cin>>row>>t)
    {
          int i,allow[120],allow1[120];
          for (i=0;i<row;i++)
          {
              cin>>s[i]>>d[i];
              allow[i]=s[i]-d[i];
              allow1[i]=allow[i];
          }
          sort (allow ,allow+row);
          if (allow[0]<10)
          cout<<"The zombies eat your brains!" << endl;
          else 
          {
               for (i=1;i<row;i++)
               if (allow[i]-allow[i-1]<10)
               {
                        cout << "The zombies eat your brains!" << endl;   
                        break;
               }
               if (i==row)
               {
                          for (int j=0;j<row;j++)
                          {
                              if (j!=0)
                              cout<<" ";
                              cout<<m(allow[j],allow1,row);    
                          }
                          cout<<endl;
               }
          }
    }
    //system ("pause");
    return 0;
}     

/////1626
#include <iostream>
using namespace std;
    int x[25][25][25]={0};
    int w(int a,int b,int c)
    {
        if (a<=0||b<=0||c<=0)
        return 1;
        if (a>20||b>20||c>20)
        return w(20,20,20);
        if (x[a][b][c])
        {
         return x[a][b][c];
        }
        if (a<b&&b<c)
        {
         x[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
         return x[a][b][c];
        }
        else {
             x[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
             return x[a][b][c];
        }
    }
    int main ()
    {
        int a,b,c;
        while (cin>>a>>b>>c&&(a!=-1||b!=-1||c!=-1))
        {
              cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl;
        }
        //system ("pause");
        return 0;
    }

////////1574
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
    double a[12],eve,sum=0;
    for (int i=0;i<12;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    cout<<"$"<<setprecision(2)<<fixed<<sum/12<<endl;
    //system ("pause");
    return 0;
}

/////////3469
#include <iostream>
using namespace std;
int s(int a,int b)
{
    int m=a,n=b,c;
    if (a<b)
    {
            int temp=a;
            a=b;
            b=temp;
    }
    while (b)
    {
          c=a%b;
          a=b;
          b=c;
    }
    return a;
}
int main ()
{
    int t;
    cin>>t;
    while (t--)
    {
          int m,n,b1,b2;
          cin>>m>>n>>b1>>b2;
          cout<<s(m-b1,n-b2)<<endl;
    }
    //system ("pause");
    return 0;
}

///////3488
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,t;
    cin>>n;
    while(n--){
        cin>>t;
        int sun=0;
        int a[100500];
        for(int i=0;i<t;i++){
            cin>>a[i];
        }
            sort(a,a+t);
            for(int i=0;i<t-1;i++){
                a[i+1]+=a[i];
                sun+=a[i+1];
                for(int j=i+1;j<t-1;j++){
                    if(a[j]>a[j+1])
                        swap(a[j],a[j+1]);
                    else
                        break;
                }
            }
        cout<<sun<<endl;
    }
}

///////////////2859
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    while(cin>>n&&n){
        int a[1000];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        for(int i=n-2;i>=0;i--){
            if(a[i]<a[n-1]){
                cout<<a[i]<<endl;
                break;}
        }
    }
}

/////1528
#include <iostream>
using namespace std;
    long long lcm(long long m, long long n){
    long long a = m, b = n;
    if(a < b)
        swap(a, b);
    while(b != 0){
        a = a % b;
        swap(a ,b);
    }
    return m * n / a;
}

int main() {
    int x;
    cin>>x;
    while(x--){
        int y,m,n;
        cin>>y;
        cin>>m;
        for(int i=1;i<=y-1;i++){
            cin>>n;
            m=lcm(m,n);
        }
        cout<<m<<endl;
    }
}

///////////3224
#include <iostream>
using namespace std;
int main() {
    int n;cin>>n;
    while(n--){
        long long a,b;
        cin>>a>>b;
        cout<<a*b-1<<endl;
    }
}


////3470
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=0;;i++){
            if(pow(2,i)>=n){
                cout<<i<<endl;
                break;
            }
        }
    }
}

////////3319
#include <iostream>
using namespace std;

int gcd(int a,int b){
    if(a<b) swap(a,b);
    while(b){
        a=a%b;
        swap(a,b);
        }
    return a;
}

int main(){
    int n,m,z;
    while(cin>>n>>m&&(m||n)){
          m=m+1;n=n+2;
          z=gcd(m,n);
          cout<<m/z<<" "<<n/z<<endl;
          }
}

//////3150
#include<iostream>  
using namespace std;  
int main()  
{  
    int u;
    cin>>u;
    int o=0;
    while (u--)
    {
          
          int m,n,min,max;   
          cin>>m>>n;  
          {  
          if(m>=n)
          {  
          min=n;  
          }else
          {  
          min=m;  
          }  
          while(true){  
                        if(m%min==0&&n%min==0){   
                                        break;  
                                                }  
                                        min--;  
                      }  
                                        }  
                                        {  
                                        if(m>=n)
                                        {  
                                        max=m;  
                                        }
                                        else
                                        {  
                                        max=n;  
                                        }  
                                        while(true){  
                                        if(max%m==0&&max%n==0){  

                                                                             break;  
                                                              }  
                                        max++;  
                                                   }  
                      }
                                         o++;
                                         cout<<o<<" "<<max<<" "<<min<<endl;
   }  
}

////3237
#include<string>
#include<iostream>
using namespace std;
int main()
{
    int T,B,L,R;
    string s;
    cin>>T;
    while(T--)
    {
         R=0;
         cin>>B>>s;
         for(int i=0;i<s.size();++i)
         {

               R=(R*B+s[i]-48)%10007; 
         }
         cout<<R<<endl;
    }
    return 0;
}

////3205
#include<iostream>
#include <algorithm>
using namespace std;
int main ()
{
    int n,a[100],b[100],x,c;
    while (cin>>n)
    {
          x=n;
          c=0;
          while (n--)
          {
                for (int i=0;i<x;i++)
                {
                    cin>>a[i];
                }
                sort (a,a+x);
                b[c]=a[(x-1)/2];
                c++;
          }
          sort (b,b+x);
          cout<<b[(x-1)/2]<<endl;
    }
}


////////2891
#include<iostream>  
using namespace std;  
int main(){  
    int n,T,a[21];  
    cin>>T;  
    while(T--){  
        cin>>n;  
        for(int i=0;i<n;i++)  
            cin>>a[i];  
        //i=0;  
        while(n>0){  
            for(int i=0;i<n-1;i++){  
                a[i]=a[i+1]-a[i];  
            }  
            n--;  
        }  
        cout<<a[0]<<endl;  
    }  
    return 0;  
}  


///////////////1065
#include<iostream>  
using namespace std;  
  
int main()  
{  
    int num,key;  
    cin>>key;  
    while(key--)  
    {  
        cin>>num;  
        int sum=0;  
        int temp=5;  
        while(num/temp!=0)  
        {  
            sum=sum+num/temp;  
            temp=temp*5;  
        }  
        cout<<sum<<endl;  
    }  
    return 0;  
}  

/////3471
#include <iostream>
using namespace std;
int main()
{
    int a;
    while (cin>>a&&a!=0)
    {
        if (a%3==0)
        cout<<"Unhappy"<<endl;
        else 
        cout<<"Happy"<<endl;
        
    }

    return 0;
}

////////2526
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int b,n,a,x,y;
    while(cin>>b>>n&&b!=0&&n!=0){
        for(int i=1;i<=1000000;i++){
            x=pow(i,n);
            if(x>b){
                y=pow(i-1,n);
                if(x-b>b-y) {
                    cout<<i-1<<endl;
                    break;
                }
                else {
                    cout<<i<<endl;
                    break;
                }
            }
            else if(x==b){
                cout<<i<<endl;
                break;
            }
        }
    }
}

///////1412
#include <iostream>
#include <cstdio>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    while (n--)
    {
          int x;
          cin>>x;
          int a[x];
          int sum=0,h=0;
          double s,r;
          for (int i=0;i<x;i++)
          {
              cin>>a[i];
              sum+=a[i];
          }
          s=sum/(1.0*x);
          for (int i=0;i<x;i++)
          {
              if (a[i]>s)
              h++;
          }
          r=h/(1.0*x)*100;
          printf("%.3f%%\n",r);
    }
    return 0;
}

/////3496
#include <iostream>
#include <cstdio>
using namespace std;
int a (int s)
{
    int t = 0;
    while (s > 0) {
        t = 10 * t + s % 10;
        s = s / 10;
    } 
    return t;
}
int main ()
{
    int x;
    scanf("%d",&x);       
    while (x--)
    {
          int y,u,i,o,p;
          scanf("%d%d",&y,&u);          
          i=a(y);
          o=a(u);
          p=i+o;
          cout<<p<<endl;
          cout<<endl;
          }
          return 0;
}

////////3059
#include <iostream>
using namespace std;
int main ()
{
    int x;
    cin>>x;
    while (x--)
    {
          int c;
          int d=0;
          int f=0;
          cin>>c;
          char a[c],s[c];
          for (int i=0;i<c;i++)
          {
              cin>>a[i]>>s[i];
              if(a[i]==s[i]);
               else if (a[i]=='P'&&s[i]=='R')
                   d++;
                   else if (a[i]=='P'&&s[i]=='S')
                   f++;
                       else if  (a[i]=='R'&&s[i]=='S')
                            d++;
                                else if  (a[i]=='R'&&s[i]=='P')
                                     f++;
                                         else if  (a[i]=='S'&&s[i]=='P')                     
                                              d++;
                                                  else if  (a[i]=='S'&&s[i]=='R')                     
                                                  f++;
          }
          if (d==f)
          cout<<"TIE"<<endl;
          else if (d>f)
          cout<<"Player 1"<<endl;
          else if (d<f)
          cout<<"Player 2"<<endl;
    }
          return 0;
}


////////2891
#include<iostream>
using namespace std;
int main()
{
   int x;
   cin>>x;
   while (x--)
   {
        int s,a[25];
        cin>>s;
        for (int i=0;i<s;i++)
          cin>>a[i];
          while (s--)
          {
                for (int i=0;i<s;i++)
                a[i]=a[i+1]-a[i];
          } 
    cout<<a[0]<<endl;
    }
    //system ("pause");
    return 0;
}
      


//2803
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <cstdio>
using namespace std;
int main ()
{
    int a;
    cin>>a;
    while (a--)
    {
          double a,b,c,v,x1,x2;
          cin>>a>>b>>c;
          if ((b*b-4*a*c)>=0)
          {
          v=sqrt(b*b-4*a*c);
          x1=(-b+v)/(2*a);
          x2=(-b-v)/(2*a);
          if (x1==x2)
              cout<<setiosflags(ios::fixed)<<setprecision(3)<<x1<<endl;
              else
              cout<<setiosflags(ios::fixed)<<setprecision(3)<<x2<<" "<<x1<<endl; 
          }
          else
          cout<<"No solution!"<<endl;
    }
    //system ("pause");
    return 0;
}
        
////2001
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main ()
{
    int t,n;
    string s[11];
    cin >> t;
    for(int k = 1;k <= t;k++)
    {
        int ans = 0;
        cin >> n;
        for(int i = 0;i < n;i++)
        {
            cin >> s[i];
            if(s[i] == "sheep")
                ans++;
        }
        printf("Case %d: This list contains %d sheep.\n",k,ans);
        if(k != t)
            cout << endl; 
    }
    return 0;
    
}


/////2056
#include<iostream>
using namespace std;

int f[10];
int A,B,C;

void init()
{
    C=f[0];
    A=(f[2]-2*f[1]+f[0])/2;
    B=2*f[1]-1.5*f[0]-0.5*f[2];
}

void count()
{
    f[3]=A*3*3+B*3+C;
    f[4]=A*4*4+B*4+C;
    f[5]=A*5*5+B*5+C;
}

int main()
{
//    freopen("fjnu_1707.in","r",stdin);
    while(cin>>f[0]>>f[1]>>f[2])
    {
        init();
        count();
        cout<<f[3]<<" "<<f[4]<<" "<<f[5]<<endl;
    }
    return 0;
}

//////1823
#include <iostream>
#include <math.h>
using namespace std;

void c(int n){
    if(n==0)
        cout<<"-";
    else{
        c(n-1);
        for(int i=0;i<pow(3,n-1);i++){
            cout<<" ";
        }
        c(n-1);
    }
}

int main(){
    int n;
    while(cin>>n){
        c(n);
        cout<<endl;
    }
    return 0;
}

//////1279
#include <iostream>
#include <algorithm>
using namespace std;
    bool complare(int a,int b)
    {
         return a>b;
    }
    int main ()
{
    int m;
    cin>>m;
    while (m--)
    {
          int x;
          cin>>x;
          int a[x];
          int s[x];
          for (int i=0;i<x;i++)
          {
              cin >>a[i];
          }
          sort (a,a+x,complare);
          for (int i=0;i<x;i++)
          {
              s[i]=a[i]*(i+1);
          }
          sort (s,s+x,complare);
          cout<<s[0]<<endl;
    }
    //system("pause");
    return 0;
}


////////1089
#include <iostream>
using namespace std;

int happy(int n)
{
    int r,f,t,d;
    f=t=d=1;
    for (r=0;r<=n;++r)
    {
        f=f*(r==n?2:4)%29;        
        t=t*3%29;                
        d=d*22%29;                
    }
    r=(f-1)*(t-1)*(d-1)%29;        
    return r*9%29;                
}
int main()
{
    int n;
    while (cin>>n && n!=0)
    {
        cout<<happy(n%28)<<endl;
    }
    return 0;
}


/////1331
#include <stdio.h>

int p, q, r, s, i;
double ans;
int main () {
    while (~scanf("%d%d%d%d", &p, &q, &r, &s)) {
        ans = 1.0;
        if (p - q < q)
            q = p - q;
        if (r - s < s)
            s = r - s;
        for (i = 1; i <= q || i <= s; i ++) {
            if (i <= q) {
                ans = ans * (p - q + i) / i;
            }
            if (i <= s) {
                ans = ans / (r - s + i) * i;
            }
        }
        printf("%.5lf\n", ans);
    }
    return 0;
}
//////1015
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        double k;
        if (x%2==0||y%2==0)
        {
                           k=double (x*y);
                           cout<<fixed<<setprecision(2)<<"Scenario #"<<i<<":\n"<<k<<endl;
        }
        else 
        {
             k=x*y+0.41;
             cout<<fixed<<setprecision(2)<<"Scenario #"<<i<<":\n"<<k<<endl;
        }
        cout<<endl;
    }
        //system("pause");
        return 0;
}

///////1601
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
    int m;
    int h=1;
    while (cin>>m&&m)
    {
              int n=0;
          int a[1000];
          int sum=0;
          for (int i=0;i<m;i++)
          {
              cin>>a[i];
              sum+=a[i];
          }
          //cout<<sum<<endl;
          sum=sum/m;
          //cout<<sum<<endl;
          int s;
          for (int j=0;j<m;j++)
          {
              s=a[j]-sum;
              if (s>0)
              n+=s;
              }
              //cout<<n<<endl;
              cout<<"Set #"<<h<<endl;
              cout<<"The minimum number of moves is "<<n<<"."<<endl;
              h++;
              cout<<endl;
    }
              return 0;
}
        

//////3843
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include<algorithm>
using namespace std;
int main ()
{
    int a,b;
    cin>>a>>b;
    int s[4010];
    int d[160010];
    int y=0;
    for (int i=0;i<a;i++)
    {
        cin>>s[i];
    }
    sort(s,s+a);
    for (int j=0;j<b;j++)
    {
        cin>>d[j];
    }
    sort(d,d+b);
    int u=0;
    int o=0;
    while(u<a&&o<b)
    {
                   if (s[u]<d[o])
                   u++;
                   if (s[u]>d[o])
                   o++;
                   if(s[u]==d[o])
                   {
                                 u++;
                                 o++;
                                 y++;
                   }
    } 
    cout<<y<<endl;
    return 0;
}

////1805
#include<iostream>
#include<cstring>
#include<stdlib.h>
using namespace std;
int main ()
{
    int m,a;
    cin>>m;
    int s[100];
    while (m--)
    {
          int d=0;;
          cin>>a;
          for(int i=0;i<a;i++)
          {
                  cin>>s[i];
                  d+=s[i];
          }
          d+=-a+1;
          cout<<d<<endl;
    }
    return 0;
}

////////2538
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int h(int n)
{
    int y=0;
    for (int i=1;i<=n;i++)
    {
        y+=i;
    }
    //cout<<y;
    return y;
}
int main ()
{
    int u;
    cin>>u;
    int a[u];
    int t=0;
    while (u--)
    {
          int m;
          cin>>m;
          int sum=0;
          for (int o=1;o<=m;o++)
          {
              int p=h(o+1);
              //cout<<p<<endl;
              sum=sum+o*p;
              //cout<<sum<<endl;
          }
          a[t]=sum;
          cout<<t+1<<" "<<m<<" "<<a[t]<<endl;
          t++;
    }
    return 0;
}

////////3503
#include <iostream>
#include <cmath>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main ()
{
    int m;
    cin>>m;
    int a[10001];
    int g[10001];
    while (m--)
    {
          int u;
          cin>>u;
          memset(g,0,sizeof(g));
          for (int i=1;i<=u;i++)
          {
              cin>>a[i];
              for (int j=1;j<=i;j++)
                  if (a[i]==a[j])
                  g[i]++;
          }
          sort(g,g+10001);
          cout <<g[10000]<<endl;
    }
    return 0;
}

///////2800
#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
int main ()
{
    int m,n,z,x;
    cin>>m;
    while (m--)
    {
          cin>>n;
          z=n*n-n+1;
          x=n*n+n-1;
          cout<<z<<" "<<x<<endl;
          
     }  
     return 0;
}
   

/////////2994
#include <iostream>
#include <cstring>
#include<stdlib.h>
using namespace std;
int main ()
{
    int m;
    cin>>m;
     for (int r=0;r<m;r++)
    {
          int b;
          int a[10];
          int z[10];
          cin>>b;
          int n=0;
          for (int i=0;i<b;i++)
          {
              cin>>a[i];
          }
          for (int o=0;o<b;o++)
          {
              cin>>z[o];
          }
          for (int h=0;h<b;h++)
          {
              n+=a[h]*z[h];
          }
          cout <<n<<endl;
    }
    return 0;
}
      

////////3771
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include <algorithm>
using namespace std;
int main ()
{
    int m;
    cin>>m;
    char a[4][10];
    int s[4];
    int c;
    for (int u=0;u<m;u++)
    {
        c=101;
          for (int i=0;i<4;i++)
          {
              cin>>a[i]>>s[i];
              if (c>s[i])
               c=s[i];
          }
          for (int i=0;i<4;i++)
          {
              if (c==s[i])
              {
                          cout<<"Poor "<<a[i]<<endl;
                          break;
              }
          }
          
    }
    return 0;
}
        

/////3842
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
   {
        cin>>a[i];
        
   }
        for (int p=0;p<n;p++)
        {
            for (int u=0;u<n;u++)
            {
                if (a[p]<a[u])
                   swap(a[u],a[p]);
            }
        }
        for (int i=0;i<n;i++)
        {
            if(i!=n-1)
            cout<<a[i]<<" ";
            else
            cout<<a[i]<<endl;
            }

        return 0;
}
     
////////3985
# include <iostream>
# include <stdio.h>
# include <stdlib.h>
using namespace std;
int main ()
{
    int o;
    cin>>o;
        while (o--)
        { 
              int m,n,b,k,l;
              double d=1;
              cin>>m>>n>>b;
              for (b;b>0;b--)
              {
                  d=d*n/m;
                  m--;
                  n--;
              }
              printf("%.4lf\n",d);
        }

        return 0;
}

///////////1551
#include <iostream>
#include <cstring>
using namespace std;
int you(int s)
{
     int a[100];
   int w=0;
   for (int i=0;i<100;i++)
   {
       a[i]=s%10;
        if (s==0)
       a[i]=0;
       s/=10;
   }
   for (int y=0;y<100;y++)
   {
       w+=a[y];
   }
      if (w<10)
      cout<<w<<endl;
      
       else if (w>=10)
           return you(w);
}
    
int main()
{
    int sum=0;
    char str[1000];
    while (cin>>str)
    {
           int sum=0;
           if(str[0]=='0')
            break;
          for(int i=0;i<strlen(str);i++)
           sum+=str[i]-'0';
           you(sum);
          }
             return 0;
   
}

///////////////1257
#include<iostream>
#include <cstring>
using namespace std;
int  f91(int n)
{
    if (n>=101)
        return n-10;
    else
        return f91(f91(n+11));
}
int main ()
{
   int a,b;
   while (cin>>a)
   {
       if (a==0)
        break;
       else
       {
        b=f91(a);
       }
       cout <<"f91"<<"("<<a<<") "<<"= "<<b<<endl;
   }
   return 0;

}

///////3976
#include <iostream>
#include <stdlib.h>
using namespace std;

int main ( )
{
 int n;
 cin>>n;
 int m[12]={0,1,2,1,2,1,1,2,2,2,2,2};
 for (int i=0;i<n;i++)
 {
     int s;
     cin>>s;
     if (s<=11)
        cout<<"Case "<<i+1<<": "<<m[s]<<endl;
     else
     {
         int k=0,n;
         while (s>11)
         {
             s-=6;
             k++;
         }
         k=k+m[s];
         cout<<"Case "<<i+1<<": "<<k<<endl;
     }
 }
     return 0;
}

/////////3975
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
#define inf 2100000000
using namespace std;
const int mmm=105;
double M[mmm];
void  intt(){
    M[1]=0.60;
    M[2]=0.70;
    for (int t=3;t<mmm;t++)
        M[t]=0;

}
double _M(int k)
{
    if (M[k]>0)
        return M[k];
    return M[k]=_M(k-1)*0.6+_M(k-2)*0.5;
}
int main ()
{
    int n;
    int i=0;
    intt();
    int t;
    scanf("%d",&t);
    while(t--&&cin>>n){
        printf("Case %d: %.2lf\n",++i,_M(n));//??//
    }
    return 0;
}

//////////3844
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main ()
{
    int m;
    string s;
    scanf ("%d",&m);
    while (m--)
    {
        cin>>s;
        int as=0,i;
        for(i=0;i<s.length();i++)
            as=as*2+(s[i]-'0');
            i=0;
            while (as)
            {
                s[i++]=as%8+'0';
                as/=8;
            }
            for (int j=i-1;j>=0;j--)

                cout<<s[j];
            cout<<endl;


    }
}

/////////3841
#include <iostream>
using namespace std;
int n,m,k;
int main()
{


    while (cin>>n)
    {
        int sum=0;
        for (int i=0;i<n;i++)
        {
            cin>>m;
            sum+=m;
        }
        k=sum/n;
        cout<<k<<endl;
    }
    return 0;
}


/////////////1001
#include <iostream>
using namespace std;
int main ()
{
    char a;
    int z;
   while(cin>>z)
   {  
      a=z;
      cout<<a;
   }
    return 0;
}


///////////3467
#include<iostream>
#include<cstring>
using namespace std;
int main ()
{
    int x;
    int y;
    cin>>x;
    for(int i=0;i<x;i++)
    {
       cin>>y;
       int u=0;
       int o;
       int m=100000000;
       while(m>0)
       {
           o=y/m;
           y=y-o*m;
           u=u+o;
           m=m/10;
       }
      cout<<u<<endl;
    }
    return 0;
}


////2556
#include<iostream>
using namespace std;
char chr[500][500];
void fun(char ch[][500],int x,int y,int &x1,int &y1){
    if(ch[x][y]=='W')
        x1=x,y1=y-1;
    else if(ch[x][y]=='N')
        x1=x-1,y1=y;
    else if(ch[x][y]=='S')
        x1=x+1,y1=y;
    else
        x1=x,y1=y+1;

}
void fun1(int &k,int a[],int b[],int i,int &l){
    for(l=i-1;l>=0;l--){
        if(b[l]==b[i]&&a[l]==a[i]){
            k=0;
            break;
        }
    } 
}
int main()
{
     int x,y,z;
     cin>>x>>y>>z;
     while(x!=0||y!=0||z!=0){
         
         for(int i=0;i<x;i++)
         {
             for(int m=0;m<y;m++)
             {
                 cin>>chr[i][m];
             }
         }
         int a[500],b[500];
         a[0]=0,b[0]=z-1;
         int i=0,l=0,k=1;
            while(k!=0&&a[i]<x&&b[i]<y&&a[i]>=0&&b[i]>=0){
            fun(chr,a[i],b[i],a[i+1],b[i+1]);
            i++;
            fun1(k,a,b,i,l);
         }
         if(k==0)
             cout<<l<<" step(s) before a loop of "<<i-l<<" step(s)"<<endl;
         else
             cout<<i<<" step(s) to exit"<<endl;
         cin>>x>>y>>z;
     }
     return 0;
}


/////1090
#include <iostream>
#include <string.h>
using namespace std;
char c[220][220];
int ck(int &l,int a,int b){
    int h;
    for(h=1;h<a-l;h++){
        if(c[h+l][b]=='1')
            break;
    }
    l=l+h;
    return h;
}
int main(){
    int a,b;
    //char c[220][220];
    cin>>a>>b;
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++)
            cin>>c[i][j];
    }
    int k[220],max=0;
    memset(k,0,sizeof(k));
    for(int i=0;i<b;i++){
        int l=0;
        while(l<a){
            if(c[l][i]=='1')
                l++;
            else{
                int y=ck(l,a,i);
                if(max<y)
                    max=y;
                k[y]++;
            }
        }
    }
    for(int i=1;i<=max;i++){
        if(k[i]!=0)
            cout<<i<<" "<<k[i]<<endl;
    }
    return 0;
}

/////1355
#include <iostream>
using namespace std;

void p(int b[3000],int n){
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(b[j]<b[i])
                b[j]=b[i]+b[j],b[i]=b[j]-b[i],b[j]=b[j]-b[i];
        }
    }
}
int main(){
    int n;
    while(cin>>n){
        int a[3000],b[3000];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n-1;i++){
            if(a[i+1]>a[i])
                b[i]=a[i+1]-a[i];
            else
                b[i]=a[i]-a[i+1];
        }
        p(b,n-1);
        int k=0;
        for(int i=0;i<n-1;i++){
            if(b[i]!=i+1)
                k=1;
        }
        if(k==1)
            cout<<"Not jolly\n";
        else
            cout<<"Jolly\n";
    }
    return 0;
}


////2990
#include <iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int p,q,a[200],b[200];
        cin>>p;
        for(int j=0;j<p;j++)
            cin>>a[j];
        cin>>q;
        for(int k=0;k<q;k++)
            cin>>b[k];
        int m=0;
        for(int i=0;i<p;i++){
            for(int j=0;j<q;j++){
                if(a[i]+b[j]==0)
                    m++;
            }
        }
        cout<<m<<endl;
    }
    return 0;
}

////////1590
#include <string.h>
#include <iostream>
using namespace std;

char e[27];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<26;i++)
        e[i]=char(65+i);
    e[26]='A';
    for(int i=0;i<n;i++){
        char a[50];
        cin>>a;
        cout<<"String #"<<1+i<<endl;
        for(int l=0;l<strlen(a);l++){
            for(int j=0;j<26;j++){
                if(a[l]==e[j])
                    cout<<e[j+1];
            }
        }
        cout<<endl<<endl;
    }
    return 0;
}

//////2968
#include <iostream>
using namespace std;

int main(){
    int a;
    while(cin>>a){
        int b;
        cin>>b;
        int m,n;
        m=(b-1)%a,n=(b-1)/a;
        while(m>0&&n>0)
            m--,n--;
        while(m<a&&n<a){
                        if(m!=a-1&&n!=a-1)
                cout<<a*(n+1)-(a-m-1)<<" ";
                        else
                            cout<<a*(n+1)-(a-m-1);
            n++,m++;
        }
        cout<<endl;
    }
    return 0;
}


////////2857
#include<iostream>
using namespace std;
void ad(int as[])
{
    for(int i=0;i<6;i++)
    {
        int s;
        as[0]=0;
        for(int t=i;t<6;t++)
        {
            if(as[i]>as[t])
            {
                s=as[t];
                as[t]=as[i];
                as[i]=s;
            }
        }
    }

}
int main()
{
    int x;
    cin>>x;
    int a[x];
    int asd[x];
    while(x!=0)
    {
        int temp=-1;
        for(int i=0;i<x;i++)
      {
          long int q=0;
          int z, c ,v ,b,n ,m;
          cin>>a[i];
            z=a[i]/100000;
           c=(a[i]-z*100000)/10000;
           v=(a[i]-z*100000-c*10000)/1000;
           b=(a[i]-z*100000-c*10000-v*1000)/100;
           n=(a[i]-z*100000-c*10000-v*1000-b*100)/10;
           m=(a[i]-z*100000-c*10000-v*1000-b*100-n*10);
           int as[6]={z,c,v,b,n,m};
          ad(as);
          q=as[0];
          for(int i=1;i<6;i++){
            q=q*10+as[i];
          }
          asd[i]=q;

      }
          for(int i=0;i<x;i++)
        {
            if(temp<asd[i])
            {
                temp=asd[i];
            }
        }
            cout<<temp<<endl;
            cin>>x;
    }
  return 0;
}


//////3456
#include<iostream>
using namespace std;
int main()
{
    int m;
    int n;
    int o=0;
    cin>>m>>n;
    int  ch[m];
    for(int i=1;i<m;i++)
    { 
        ch[0]=n;
        cin >>ch[i];
        if(ch[i]>ch[0])
        o++;
    }
    cout<<o+1<<endl;
    return 0;
}


/////////////1445
#include<iostream>
using namespace std;

int main ()
{
    int x;
    int m;
    int n;
    cin >>x;
    for(int o=0;o<x;o++)
    {
        cin>>m>>n;
        int door[n];
        int ch[n];
        for(int t=0;t<n;t++)
        {
            cin>>door[t];
            if(door[t]>m/2)
            {
                ch[t]=m-door[t];
            }
            else
            {
              ch[t]=door[t];
            }
        }
        int max=door[0];
        for(int b=0;b<n;b++)
        {
            if(door[b]>max)
            max=door[b];
        }
        int min=door[0];
        for(int u=0;u<n;u++)
        {
            if(door[u]<min)
            min=door[u];
        }
        int asd=ch[0];
        for( int d=0;d<n;d++)
        {
            if(ch[d]>asd)
            asd=ch[d];
        }
        int q=m-min;
        if(q>max)
        cout<<asd<<" "<<q<<endl;
        else
        cout<<asd<<" "<<max<<endl;
    }
    return 0;
}

//////1191
#include <iostream>
using namespace std;

void ju(int a[20],int b[20],int &p,int &q){
    for(int i=1;i<20;i++){
        if(a[0]==a[i]&&b[0]==b[i])
            p=1;
        if(a[0]>50||a[0]<=0||b[0]>=51||b[0]<=0)
            q=1;
    }
}
int main()
{
    int n;
    cin>>n;
    while(n!=0){
        int a[20],b[20];
        for(int i=0;i<=19;i++){
            a[i]=25,b[i]=30-i;
        }
        int m[100],v[100],l=0,o=0;
        m[0]=100,v[0]=100;
        for(int d=0;d<n;d++){
            char x;
            cin>>x;
            if(x=='W'){
                for(int i=19;i>0;i--){
                    b[i]=b[i-1];
                    a[i]=a[i-1];
                }
                b[0]=b[0]-1;
                
            }
            else if(x=='E'){
                for(int i=19;i>0;i--){
                    b[i]=b[i-1];
                    a[i]=a[i-1];
                }
                b[0]=b[0]+1;
            }
            else if(x=='N'){
                for(int i=19;i>0;i--){
                    b[i]=b[i-1];
                    a[i]=a[i-1];
                }
                a[0]=a[0]+1;
            }
            else if(x=='S'){
                for(int i=19;i>0;i--){
                    b[i]=b[i-1];
                    a[i]=a[i-1];
                }
                a[0]=a[0]-1;
            }
            int p=0,q=0;
            ju(a,b,p,q);
            if(p==1){
               m[l]=d+1;
               l++;
            }
            else if(q==1){
                v[o]=d+1;
                o++;
            }   
        }
        if(m[0]!=0&&m[0]<v[0])
            cout<<"The worm ran into itself on move "<<m[o]<<".";
        else if(v[0]!=0&&v[0]<m[0])
            cout<<"The worm ran off the board on move "<<v[0]<<".";
        else
            cout<<"The worm successfully made all "<< n <<" moves.";
        cout<<endl;
        cin>>n;
    }
    return 0;
}

//////1350
# include<iostream>
# include<cstring>
using namespace std;
int main()
{
    int m;
    int x,y;
    int ch[10];
    int door[10];
    cin>>x;
    cin>>y;
    while(x!=0||y!=0)
    { 
        int e=0;
        int u=0;
        int j=0;
        int i=0;
        for(int r=0;r<10;r++)
        {
          if(x!=0)
          {
            ch[i]=x-(x/10)*10;
            x=x/10;
            i++;
          }
          else
          ch[r]=0;
          if(y!=0)
          {
            door[j]=y-(y/10)*10;
            y=y/10;
            j++;
          }
          else
          door[r]=0;
        }
        
       
        if(i>=j)
        {
            m=i;
        }
        else
        {    
        m=j;
        }
        for(int t=0;t<m;t++)
        {
            u=ch[t]+door[t]+u/10;
            if(u>=10)
            e++;
        }
        if(e==0)
        cout<<"No carry operation."<<endl;
        else if(e==1)
        cout<<"1 carry operation."<<endl;
        else
        cout<<e<<" carry operations."<<endl;
        cin>>x>>y;
        }
    return 0;
}


//////2967
#include<iostream>
using namespace std;
int main()
{
    int g;
    cin>>g;
    while(g!=-1)
    {
         if(g==1)
        {
         int x;
         cin>>x;
         int temp;
         temp=x;
           for (int i=0;i<x;i++)
            {
                 for(int a=0;a<temp-1;a++)
                 {
                   cout<<" ";
                 }
                 for (int q=0;q<(2*i+1);q++)
                 {
                  cout<<"*";
                  }
             cout<<endl;
             temp --;
             }
    }
    else if(g==2)
    {
        int m,z;
        cin>>m;
        cin>>z;
        int asd;
        asd=z;
        for(int p=0;p<z;p++)
        {
               for(int y=0;y<asd-1;y++)
             {
               cout<<" ";
             }
        for(int u=0;u<m;u++)
           {
            cout<<"*";
            }
        cout<<endl;
        asd--;
         }
    }
    else if (g==3)
         {
                int k,f;
                cin>>k;
                cin>>f;
                for(int h=0;h<f;h++)
                {
                    for(int e=0;e<k;e++)
                    {
                        cout<<"*";
                    }
                    cout<<endl;
                }
         }
         cout<<endl;
         cin>>g;
    }
    return 0;
}

////////1477
#  include <iostream>
using namespace std ;
int main()
{
    int m;
    int x;
    int k=0;
    cin>>m;
    for(int i=0;i<m;i++)
    {
            cin>>x;
            k=0;
            while (x!=0)
            {
                  if(x%2==1)
                  {
                  x=x/2;
                  if  (x!=0) {cout<<k<<" ";}
                  }
                  else
                  {
                  x=x/2;
                  }
                  k++;
             }
             cout<<k-1<<endl;
    }
    return 0;
}

////////1476
#include <iostream>
using namespace std;

int main ()
{
    int m,x,temp;
    int k=0;
    cin>>m;
    for(int i=0;i<m;i++)
    {
       cin>>x;
       k=0;
       if(x%2==0)
       {
             while(x%2==0)
          {
             x=x/2;
             k++;
             temp=x;
          }
          cout<<temp<<" "<<k<<endl;
       }
       else
       cout<<x<<" 0"<<endl;
    }
    return 0;
}

/////////1153
# include <iostream>
# include<string.h>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    cin.get();
    for(int i=0;i<n;i++)
    {
        char a[100];
        int c[100],k=1;
        cin.getline(a,100);
        for(int i=0;i<strlen(a);i++)
        {
            if(a[i]==' ')
            {
                c[k]=i;
                k++;
            }
        }
        c[0]=-1,c[k]=strlen(a);
        for(int i=0;i<=k-1;i++)
        {
            for(int l=c[i+1]-1;l>c[i];l--)
            cout<<a[l];
            if(i!=k-1)
            cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}


///////////1644
# include <iostream>
#include <cstring>
using namespace std;
int main ()
{
    int x;
    cin >>x;
    char ch[100];
    cin.getline(ch,100);
    for (int i=0;i<x;i++)
    {

        cin.getline(ch,100);
    
        for(int m=strlen(ch)-1;m>=0;m--)
        {
            cout <<ch[m];
        }
        cout << endl;
     }
     return 0;
}

///////1575

#include <iostream>
using namespace std;

int main()
{
    int b;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
            double doors[2];
            {
                cin >> doors[0];
                cin>>doors[1];
            }
               double a=((doors[0]*doors[0]+doors[1]*doors[1])*3.14)/2;
               b=int (a/50);
               cout<<"Property "<<i<<": "<<"This property will begin eroding in year "<<b+1<<"."<<endl;
    }
    cout<<"END OF OUTPUT."<<endl;
    return 0;
}

///////////2243
 # include <iostream>
using namespace std;

int main ()
{
    int n;
    cin>>n;
    int m=0;
    int doors[1000];
    while (n!=0)
    {
          doors[m]=1;
          while (n!=1)
          {
                
                if (n%2==0)
                {
                n=n/2;
                }
                else
                {
                n=3*n+1;
                }
               doors[m]++; 
            }
          m++;
          cin>>n;
     }
     for(int z=0;z<m;z++)
     {
      cout<<doors[z]<<endl;
     }
     return 0;
}


////////2076
# include <iostream>
using namespace std;

int ada(int x)
{    
     int m=0;
     for (int a=1;a<=x;a++)
     {
         int q=1;
         for (int i=1;i<=a;i++)
         {   
             if (a%i==0)
             q++;
         } 
         if (q%2==0)
           {
             m++;
           }
     }
     return m;
}

int main ()
{    int n;
     cin>>n;
     int doors[n];      
     for (int z=0;z<n;z++)
     {
        int y;
        cin >>y;
        doors[z]= ada (y);
     }
     for (int z=0;z<n;z++)
     {
         cout <<doors[z]<<endl;
     }
      return 0;
}

///////2051
# include <iostream>
using namespace std;
int main ()
{   int x=168;
    int n=0;
    int m=0; 
    int number[3];
    int a[3];
    int b[3];
    for(int i=0;i<3;i++)
    {
            cin >>number[i];
            if (number[i]>x)
            {
                            
                a[n]=number[i];
                n++;
            }   
            else
            {
                b[m]=number[i];
                m++;
            }
    }         
          int i;
          for(i=0;a[i]>0;i++);
          if (i==3)
          { 
                  cout <<"NO CRASH";
          }
          else
          {
              cout<<"CRASH ";
              for (int x=0;x<m;x++)
              {
                 
              cout<< b[x]<<endl;
              break;
              }
          }
   return 0;
}      


///1939
# include <iostream>
using namespace std;
int main()
{
    int n;
    cin >>n;
    int x=0; 
    int ball[x+1];
    while(n!=-1)
    {
              
              int numbers[n];
              int doors[n];
              cin>>numbers[0];
              cin >>doors[0];
              int q=numbers[0]*doors[0];
              for(int i=1;i<n;i++)
              {
                  cin>> numbers[i];
                  cin>> doors[i];
                  q=q+numbers[i]*(doors[i]-doors[i-1]);
              }
              ball[x]=q;
              x++;
              cin >>n;
    }
              for(int m=0;m<x;m++)
              {
               cout<<ball[m]<<" miles"<<endl;
              }       
    return 0;
}  

 

posted @ 2017-03-30 15:39  xcsllll  阅读(401)  评论(0编辑  收藏  举报