@Пaтрик
417 / 392 / 40
Регистрация: 21.01.2012
Сообщений: 972
|
27.08.2012, 20:55
|
|
C++ | 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
| #include <iostream>
#include <cstring>
#include <algorithm>
struct User
{
int id;
char nickname[51];
int karma;
};
bool cmp_by_nick_length(const User& user1, const User& user2)
{
return std::strlen(user1.nickname) < std::strlen(user2.nickname);
}
int main()
{
User user[] = {
{ 15, "picknick", 0 },
{ 18, "Ololoh", 0 },
{ 15, "AlexeyZakharenkov", 0 },
{ 18, "Tanya", 0}
};
std::sort(std::begin(user), std::end(user), cmp_by_nick_length);
for(int i = 0; i < 4; i++)
std::cout << user[i].nickname << std::endl;
} |
|
0
|