jzxx1057 allowed to be tied to the ranked __ array

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.