#8052: 分享C++(使用STL)的解法


rosynirvana (rosynirvana)

學校 : 不指定學校
編號 : 33880
來源 : [182.114.3.244]
最後登入時間 :
2017-07-24 00:02:04

#include <iostream>
#include <algorithm>
#include <vector>

bool comp(int i, int j);

int main()
{
int n;
while(std::cin >> n){
std::vector<int> buf;
for(int i=0; i!=n; ++i){
int temp;
std::cin >> temp;
buf.push_back(temp);
}
std::sort(buf.begin(), buf.end(), comp);
for(std::vector<int>::const_iterator iter = buf.begin(); iter != buf.end(); ++iter)
std::cout << *iter << " ";
std::cout << "\n";
}
return 0;
}

bool comp(int i, int j)
{
if(i % 10 < j % 10)
return true;
if(i % 10 > j % 10)
return false;
if(i / 10 > j / 10)
return true;
return false;
}