Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdlib.h>
- using namespace std;
- int main()
- {
- //put N
- int n;
- cin>>n;
- //put kid's lovers
- int luv[1000]={0};
- for(int i=1;i<=n;i++)
- {
- cin>>luv[i];
- if(luv[i]==i)
- {
- cout<<"Someone is narcissist(自戀狂)!"<<endl;
- system("pause");
- return 0;
- }
- }
- //check who's the most popular kid
- int c_luv[1000]={0},k=0,max1=0,max2=0,c=9;
- for(int i=1;i<=n;i++)
- {
- k+=luv[i];
- c_luv[k]++;
- k=0;
- }
- for(int i=1;i<=n;i++)
- {
- if(c_luv[i]>max1)
- {
- max1=c_luv[i];
- max2=i;
- c=9;
- }
- // here check peace situation
- else if(max1!=0&&max1==c_luv[i])
- {
- c=1;
- }
- }
- //if it's peace situation,end process.
- if(c==1)
- {
- cout<<"NO"<<endl;
- system("pause");
- return 0;
- }
- //cout ans!!
- //who's the most popular kid
- cout<<endl<<max2<<endl;
- //who luv him/her(I hate the "-" between them)
- //first slove the max num's "-" problem
- //if you don't slove that
- //it'll cout 1-2-3-
- //but the ques wants you cout 1-2-3
- int check=0;
- for(int i=n;i>=0;i--)
- {
- if(luv[i]==max2)
- {
- check+=i;
- i-=100;
- }
- }
- for(int i=1;i<=n;i++)
- {
- if(luv[i]==max2&&i!=check)
- cout<<i<<"-";
- else if(i==check)
- cout<<i;
- }
- cout<<endl;
- //total
- cout<<"Total:"<<max1<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement