jzxx1057 allowed to rank in parallel
Time limit 1000MS/16MB
Topic Description In the various competitions we participate in, we often encounter the way to allow parallel rankings. For example, four contestants scored 50, 80, 50, and 30, then 80 scored first, 50 of two were second, and 30 were fourth. Write a program that calculates the position of a contestant in this ranking (front of a high score). Enter The first behavior an integer n, representing the number of contestants,1<=n<=100; the second behavior n integers, indicating the performance of each contestant; the third act an integer m representing the result of the contestant to be queried. The output has only one integer that represents the player's rank. Sample Input 4 samples Output 2
Code
#include <iostream>
using namespace std;
int a[101];
int main () {
int n,m;
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i];
cin>>m;
for (int i=1; i<=n-1; i++) { //select sort
int k=i;
for (int j=i+1; j<=n; j + +)
if (a[k]<a[j]) k=j;
if (k!=i)
{int t=a[k]; a[k]=a[i]; a[i]=t}
}
for (int i=1; i<=n; i++)
if (M==a[i]) {
cout<<i<<endl;
break;
return 0;
}