-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer Terminal.cpp
More file actions
41 lines (35 loc) · 1.11 KB
/
Container Terminal.cpp
File metadata and controls
41 lines (35 loc) · 1.11 KB
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
int n;
cin >> n; cin.ignore();
for (int i = 0; i < n; i++) {
string line;
getline(cin, line);
vector<char> stacks; // верхушки стопок
for (char c : line) {
bool placed = false;
// ищем первую стопку, верх которой >= текущей буквы
for (size_t j = 0; j < stacks.size(); ++j) {
if (stacks[j] >= c) {
stacks[j] = c; // кладём сюда (обновляем верх)
placed = true;
break;
}
}
if (!placed) {
stacks.push_back(c); // создаём новую стопку
}
}
// ответ для этой строки
cout << stacks.size() << endl;
}
}