#include <iostream>
#include <string>
constexpr int magic_number = 123;
bool isCollision(int a, int b) {
int diff1 = a > b ? a - b : b - a;
int diff2 = a > b ? 1000 - a + b : 1000 - b + a;
if (diff1 == magic_number || diff2 == magic_number) {
return true;
}
return false;
}
void encrypt(int &a, int &b) {
int number = magic_number;
if (isCollision(a, b)) {
number += 1;
}
a = (a+number)%1000;
b = (b+number)%1000;
}
void decrypt(int &c, int &d) {
c = c - magic_number < 1 ? 1000 - ((c - magic_number) * -1) : c - magic_number;
d = d - magic_number < 1 ? 1000 - ((d - magic_number) * -1) : d - magic_number;
if (isCollision(c - 1, d - 1)) {
c = c - 1;
d = d - 1;
}
c = c == 0 ? 1000 : c;
d = d == 0 ? 1000 : d;
}
bool test(int a, int b) {
int temp_a = a, temp_b = b;
encrypt(temp_a, temp_b);
int c = temp_a, d = temp_b;
decrypt(temp_a, temp_b);
if (temp_a != a || temp_b != b) {
std::cout << temp_a << " " << temp_b << " != " << a << " " << b << std::endl;
return true;
}
if (a == c || b == c || a == d || b == d) {
std::cout << a << " " << b << " <=> " << c << " " << d << std::endl;
return true;
}
return false;
}
int main() {
// int errors = 0;
// for (int i = 1; i <= 1000; i++) {
// for (int j = 1; j <= 1000; j++) {
// if (i != j) {
// errors += test(i, j);
// }
// }
// }
// std::cout << "Done: " << errors << std::endl;
// // while (true) {
std::string name;
std::cin >> name;
int num1 = 0, num2 = 0;
std::cin >> num1 >> num2;
if (name == "Algosia") {
encrypt(num1, num2);
std::cout << num1 << " " << num2 << "\n";
}
else {
decrypt(num1, num2);
std::cout << num1 << " " << num2 << "\n";
}
std::cout.flush();
// }
return 0;
}
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 | #include <iostream> #include <string> constexpr int magic_number = 123; bool isCollision(int a, int b) { int diff1 = a > b ? a - b : b - a; int diff2 = a > b ? 1000 - a + b : 1000 - b + a; if (diff1 == magic_number || diff2 == magic_number) { return true; } return false; } void encrypt(int &a, int &b) { int number = magic_number; if (isCollision(a, b)) { number += 1; } a = (a+number)%1000; b = (b+number)%1000; } void decrypt(int &c, int &d) { c = c - magic_number < 1 ? 1000 - ((c - magic_number) * -1) : c - magic_number; d = d - magic_number < 1 ? 1000 - ((d - magic_number) * -1) : d - magic_number; if (isCollision(c - 1, d - 1)) { c = c - 1; d = d - 1; } c = c == 0 ? 1000 : c; d = d == 0 ? 1000 : d; } bool test(int a, int b) { int temp_a = a, temp_b = b; encrypt(temp_a, temp_b); int c = temp_a, d = temp_b; decrypt(temp_a, temp_b); if (temp_a != a || temp_b != b) { std::cout << temp_a << " " << temp_b << " != " << a << " " << b << std::endl; return true; } if (a == c || b == c || a == d || b == d) { std::cout << a << " " << b << " <=> " << c << " " << d << std::endl; return true; } return false; } int main() { // int errors = 0; // for (int i = 1; i <= 1000; i++) { // for (int j = 1; j <= 1000; j++) { // if (i != j) { // errors += test(i, j); // } // } // } // std::cout << "Done: " << errors << std::endl; // // while (true) { std::string name; std::cin >> name; int num1 = 0, num2 = 0; std::cin >> num1 >> num2; if (name == "Algosia") { encrypt(num1, num2); std::cout << num1 << " " << num2 << "\n"; } else { decrypt(num1, num2); std::cout << num1 << " " << num2 << "\n"; } std::cout.flush(); // } return 0; } |
English