#include <iostream>
using namespace std;
int T, x, y, n;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> x >> y >> n;
int k;
if ((n / x) * x + y <= n) cout << (n / x) * x + y << "\n";
else cout << (n / x - 1) * x + y << "\n";
}
return 0;
}
A - Required Remainder
#include <iostream>
using namespace std;
int T, N;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> N;
int tr = 0;
if (N == 0) {
cout << "0\n";
continue;
}
unsigned long long n = N;
while (n != 1) {
if (n % 6 == 0) {
tr += 1;
n /= 6;
}
else if (n % 3 == 0) {
tr += 2;
n /= 3;
}
else {
tr = -1;
break;
}
}
cout << tr << "\n";
}
return 0;
}
B - Multiply by 2, divide by 6
#include <iostream>
#include <string>
using namespace std;
int T, L;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> L;
string s = "";
for (int i = 0; i < L; ++i) {
char input;
cin >> input;
s += input;
}
int cnt = 0, res = 0;
for (int i = 0; i < L; ++i) {
if (s[i] == '(') cnt++;
else {
if (cnt == 0) res++;
else cnt--;
}
}
cout << res << "\n";
}
return 0;
}
C - Move Brackets
'알고리즘 > Codeforces' 카테고리의 다른 글
Codeforces Round #660 (Div. 2) AB (0) | 2020.08.06 |
---|---|
Educational Codeforces Round 92 (Rated for Div. 2) A (0) | 2020.08.06 |
Codeforces Round #658 (Div. 2) AB (0) | 2020.08.06 |
Codeforces Round #661 (Div. 3) ABC (0) | 2020.08.06 |
Codeforces Round #656 (Div. 3) ABC (0) | 2020.08.06 |
댓글