-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay3.cpp
More file actions
82 lines (76 loc) · 1.7 KB
/
Day3.cpp
File metadata and controls
82 lines (76 loc) · 1.7 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
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
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
#define int long long
#define allr(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define ld long double
#define INF (int)(1e18)
#define MOD 1000000007
using namespace std;
int getMaxInd(string s) {
char mx = '0';
int ind = 0;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] > mx) {
mx = s[i];
ind = i;
}
}
return ind;
}
void Part1() {
string s;
int ans = 0;
while (cin >> s && s != "?") {
int ind = getMaxInd(s), sind = ind + 1;
string x = "";
x += s[ind];
char mx = '0';
for (int i = ind + 1; i < s.size(); i++) {
if (s[i] > mx) {
mx = s[i];
sind = i;
}
}
x += s[sind];
ans += stoll(x);
}
cout << ans << endl;
}
void Part2() {
int ans = 0;
string s;
while (cin >> s && s != "?") {
int n = s.size();
int nextind = -1;
string x = "";
for (int i = 0; i < 12; i++) {
char mx = '0';
int ind = 0;
int rem = 11 - i;
int l = n - rem;
for (int j = nextind + 1; j < l; j++) {
if (s[j] > mx) {
mx = s[j];
ind = j;
}
}
x += s[ind];
nextind = ind;
}
ans += stoll(x);
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("promote.in","r",stdin);
// freopen("promote.out","w",stdout);
int tests = 1;
// cin >> tests;
while (tests--) {
//Part1();
// Part2();
}
}