2023 day 1-3: touchup C++ cin input

This commit is contained in:
eriedaberrie 2023-12-03 16:15:40 -08:00
parent 76f255371f
commit 5a9a3ff312
5 changed files with 25 additions and 47 deletions

View file

@ -20,11 +20,7 @@ int main() {
int ret = 0;
string line;
for (;;) {
getline(cin, line);
if (cin.eof())
break;
while (getline(cin, line) && !line.empty()) {
int pi = INT_MAX, pl = -1, vi = 0, vl = 0;
for (int i = 0; i < line.size(); i++) {
unsigned char c = line[i] - '0';

View file

@ -5,28 +5,23 @@ int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto& cin = std::cin >> noskipws;
int ret = 0, id = 0;
bool isPossible = true;
for (;;) {
char c;
cin >> c;
switch (c) {
while (!cin.eof()) {
switch (cin.get()) {
case 'G':
cin >> c; cin >> c; cin >> c; cin >> c;
cin.ignore(4);
cin >> id;
break;
case ':': case ',': case ';':
if (!isPossible)
break;
cin >> c;
cin.ignore(1);
int n;
cin >> n;
cin >> c;
cin >> c;
switch (c) {
cin.ignore(1);
switch (cin.get()) {
case 'r':
if (n > 12)
isPossible = false;
@ -42,16 +37,16 @@ int main() {
}
break;
case '\n':
if (cin.eof())
goto end;
if (isPossible)
case EOF:
if (isPossible) {
ret += id;
else
id = 0;
} else {
isPossible = true;
}
break;
}
}
end:
cout << ret << '\n';
}

View file

@ -5,39 +5,32 @@ int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto& cin = std::cin >> noskipws;
int ret = 0, id = 0, r = 0, g = 0, b = 0;
for (;;) {
char c;
cin >> c;
switch (c) {
while (!cin.eof()) {
switch (cin.get()) {
case 'G':
cin >> c; cin >> c; cin >> c; cin >> c;
cin.ignore(4);
cin >> id;
break;
case ':': case ',': case ';':
cin >> c;
cin.ignore(1);
int n;
cin >> n;
cin >> c;
cin >> c;
switch (c) {
cin.ignore(1);
switch (cin.get()) {
case 'r': r = max(n, r); break;
case 'g': g = max(n, g); break;
case 'b': b = max(n, b); break;
}
break;
case '\n':
if (cin.eof())
goto end;
case EOF:
ret += r * g * b;
r = 0; g = 0; b = 0;
break;
}
}
end:
cout << ret << '\n';
}

View file

@ -10,13 +10,10 @@ int main() {
cin.tie(0);
vector<string> lines;
do {
string line;
getline(cin, line);
if (line.empty())
break;
string line;
while (getline(cin, line) && !line.empty()) {
lines.push_back(line);
} while (!cin.eof());
}
int ret = 0;

View file

@ -10,13 +10,10 @@ int main() {
cin.tie(0);
vector<string> lines;
do {
string line;
getline(cin, line);
if (line.empty())
break;
string line;
while (getline(cin, line) && !line.empty()) {
lines.push_back(line);
} while (!cin.eof());
}
int ret = 0;