struct-sort () swap ()

Source: Internet
Author: User
Problem Description: Another test, LJW decided to relax, turned on the TV, saw the basketball game, he immediately thought of the annual NBA Championship team. As a result of the review of tension, he only remembers part of the content of the memory is correct, may not be in chronological order, the contents of the memory may be duplicated. Now ask to learn programming you help LJW, to output the championship team by time (cannot repeat). (NBA from 1947A. D to A.D) input requirements: The first line is an integer n (0 8 0). The next n rows, each row is the city name (from large to lowercase letters, spaces), followed by the time (composed of numbers) separated by a space. Output requirements: A total of n rows, that is, after the ranking of the NBA Championship team. Each line is time, followed by the city name. Input Sample 3 Boston 1963 Boston 1959 Philly 1947 output Example 1947 Philly 1959 Boston 1963 Boston
Code:
#include iostream
#include algorithm
#include Cstdio
using namespace Std;
#define N 100
#define M 10
typedef struct {
int time;
Char Team[m];
}champion;
INT CMP (const champion &A, const CHAMPION&B) {
if (A.time > B.time)
return 1;
Else
return 0;
}
int main ()
{
int n,i,j;
cin>>n;
GetChar ();
Champion C[n];
for (i=0;i

cin>>c[i].team>>c[i].time;
}
for (i=0;i
for (j=0;j
if (c[j].time>c[j+1].time)
Swap (c[j],c[j+1]);
{
T=c[j].time;
C[j].time=c[j+1].time;
c[j+1].time=t;
}

Sort (c,c+n,cmp);
for (i=0;i
cout<<c[i].team<< "" <<c[i].time<<endl;
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.