-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortofsorting.cpp
72 lines (58 loc) · 1.53 KB
/
sortofsorting.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @file sortofsorting.cpp
* @author William Weston
* @brief Sort of Sorting Problem From Kattis
* @version 0.1
* @date 2023-07-22
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/sortofsorting
*/
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
auto main() -> int
{
for ( auto n = int{}; std::cin >> n; )
{
if ( n == 0 )
break;
auto last_names = std::vector<std::string>();
last_names.reserve( n );
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
for ( auto tmp = std::string(); n--; )
{
std::getline( std::cin, tmp );
last_names.push_back( std::move( tmp ) );
}
auto comp = [] ( std::string const& lhs, std::string const& rhs)
{
if ( lhs[0] == rhs[0] )
{
if ( lhs[1] == rhs[1] )
return false;
return lhs[1] < rhs[1];
}
return lhs[0] < rhs[0];
// if ( lhs[0] < rhs[0] )
// return true;
// else if ( lhs[0] > rhs[0] )
// return false;
// else
// {
// if ( lhs[1] < rhs[1] )
// return true;
// }
// return false;
};
std::stable_sort( last_names.begin(), last_names.end(), comp );
for ( auto const& elem : last_names )
std::cout << elem << '\n';
std::cout << '\n';
}
return EXIT_SUCCESS;
}