Pages

Wednesday, June 6, 2012

11462 - Age Sort

Very simple problem, since the range of values is defined and is not large you can use a O(n) algo for sorting, but even inbuilt O(nlgn) would do.


//
// main.cpp
// 11462 - Age Sort
//
// Created by Panks on 06/06/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main (int argc, const char * argv[])
{
int t, tmp;
vector<int> store;
while (scanf("%d",&t)&&t) {
while (t--) {
scanf("%d", &tmp);
store.push_back(tmp);
}
sort(store.begin(), store.end());
for (int i=0; i<store.size(); i++) {
printf("%d", store[i]);
if (i!=store.size()-1) {
printf(" ");
}
}
printf("\n");
store.clear();

}
return 0;
}

No comments:

Post a Comment