Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * problem link: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3107
- *
- * */
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- string hexa(int x) {
- string s;
- while (x > 0) {
- s += (x % 16 > 9 ? 'A' + (x % 16 - 10) : '0' + x % 16);
- x /= 16;
- }
- while (sz(s) < 2) s += '0';
- reverse(all(s));
- return s;
- }
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int testcase;
- cin >> testcase;
- for (int test = 1; test <= testcase; test++) {
- string s;
- cin >> s;
- vector<int> arr(100);
- int p = 0;
- for (int i = 0; i < sz(s); i++) {
- if (s[i] == '+') arr[p] = (arr[p] + 1) % 256;
- else if (s[i] == '-') arr[p] = (arr[p] - 1 + 256) % 256;
- else if (s[i] == '>') p = (p + 1) % 100;
- else if (s[i] == '<') p = (p - 1 + 100) % 100;
- }
- cout << "Case " << test << ": ";
- for (int i = 0; i < 100; i++) {
- cout << hexa(arr[i]) << " \n"[i == 99];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment