UVa 11462 Age Sort
很偷懶...這題用counting sort說不定比較快
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* UVa 11462 Age Sort (AC) | |
* Author: chchwy | |
* Last Modified: 2009.11.22 | |
*/ | |
#include<iostream> | |
#include<sstream> | |
using namespace std; | |
int p[2000000]; | |
int main() | |
{ | |
string line; | |
while (getline(cin, line)) | |
{ | |
int numPeople = atoi( line.c_str() ); | |
if (numPeople == 0) break; | |
getline(cin, line); | |
istringstream sin(line); | |
int i = 0; | |
while (sin >> p[i++]); | |
sort(p, p + numPeople); | |
for (int i = 0; i < numPeople - 1; ++i) | |
printf("%d ", p[i]); | |
printf("%d\n", p[numPeople - 1]); | |
} | |
return 0; | |
} |
留言
張貼留言