Advertisement
realever15

小朋友喜歡誰o(^^)o ??

May 30th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. using namespace std;
  4. int main()
  5. {
  6.     //put N
  7.     int n;
  8.     cin>>n;
  9.    
  10.     //put kid's lovers
  11.     int luv[1000]={0};
  12.    
  13.     for(int i=1;i<=n;i++)
  14.     {
  15.      cin>>luv[i];
  16.      if(luv[i]==i)
  17.       {
  18.        cout<<"Someone is narcissist(自戀狂)!"<<endl;
  19.        system("pause");
  20.        return 0;
  21.       }      
  22.     }
  23.    
  24.     //check who's the most popular kid
  25.    
  26.     int c_luv[1000]={0},k=0,max1=0,max2=0,c=9;
  27.    
  28.     for(int i=1;i<=n;i++)
  29.     {
  30.      k+=luv[i];
  31.      c_luv[k]++;
  32.      k=0;
  33.     }
  34.    
  35.     for(int i=1;i<=n;i++)
  36.     {
  37.      
  38.      if(c_luv[i]>max1)
  39.      {
  40.       max1=c_luv[i];
  41.       max2=i;
  42.       c=9;
  43.      }
  44.    
  45.     // here check peace situation
  46.     else if(max1!=0&&max1==c_luv[i])
  47.      {
  48.       c=1;
  49.      }
  50.    
  51.     }
  52.     //if  it's peace situation,end process.
  53.     if(c==1)
  54.     {
  55.      cout<<"NO"<<endl;
  56.      system("pause");
  57.      return 0;
  58.     }
  59.    
  60.     //cout ans!!
  61.    
  62.     //who's the most popular kid
  63.     cout<<endl<<max2<<endl;
  64.    
  65.     //who luv him/her(I hate the "-" between them)
  66.     //first slove the max num's "-" problem
  67.     //if you don't slove that
  68.     //it'll cout 1-2-3-
  69.     //but the ques wants you cout 1-2-3
  70.     int check=0;
  71.     for(int i=n;i>=0;i--)
  72.     {
  73.      if(luv[i]==max2)
  74.      {
  75.       check+=i;
  76.       i-=100;
  77.      }
  78.     }
  79.    
  80.    
  81.     for(int i=1;i<=n;i++)
  82.     {
  83.      if(luv[i]==max2&&i!=check)
  84.      cout<<i<<"-";
  85.      else if(i==check)
  86.      cout<<i;
  87.     }
  88.     cout<<endl;
  89.    
  90.     //total
  91.     cout<<"Total:"<<max1<<endl;
  92.    
  93.     system("pause");
  94.    
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement