L1-021
Thinking:
cyclic output
codes:
#include<bits/stdc++.h>
using namespace std;
int main() {
int k = 3;
while(k--) puts("I'm gonna WIN!");
return 0;
}
L1-022
Thinking:
determining parity counting
codes:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, x = 0, y = 0;
cin >> n;
while(n--){
int a;
cin >> a;
if(a & 1) ++x;
else ++y;
}
cout << x << ' ' << y;
return 0;
}
L1-023
Thinking:
Count
Code:
#include<bits/stdc++.h>
using namespace std;
char a[4] = {'G', 'P', 'L', 'T'};
int cnt[4];
int main() {
string s;
cin >> s;
for(char & c : s) {
c = toupper(c);
for(int i = 0; i < 4; i++) {
if(c == a[i]) { ++cnt[i]; break; }
}
}
while(true) {
bool ans = 0;
for(int i = 0; i < 4; i++) {
if(cnt[i]) putchar(a[i]), --cnt[i], ans = true;
}
if(!ans) break;
}
return 0;
}
L1-024
Ideas:
+2, more on the reduction
of code:
#include<bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
x += 2;
if(x <= 7) cout << x;
else cout << x - 7;
return 0;
}
L1-025
Ideas:
the string to detect
the code:
#include<bits/stdc++.h>
using namespace std;
int deal(string & s){
for(char & c : s){
if(c < '0' || c > '9') return -1;
}
int num = stoi(s);
if(num < 1 || num > 1000) return -1;
return num;
}
#define ELSE else putchar('?')
int main() {
string a, b;
cin >> a;
getchar();
getline(cin, b);
int x = deal(a), y = deal(b);
if(~x) cout << a; ELSE;
cout << " + ";
if(~y) cout << b; ELSE;
cout << " = ";
if((~x) && (~y)) cout << x + y; ELSE;
return 0;
}