#include <iostream> #include <utility> #include <tuple> std::tuple<long, long, bool> cramer(long a, long b, long c, long d, long e, long f) { long x1 = e*d-b*f; long x2 = a*d-b*c; if (x1%x2 != 0) return {0,0,false}; long y1 = a*f-e*c; long y2 = a*d-b*c; if (y1%y2 != 0) return {0,0,false}; return {x1/x2, y1/y2, true}; } struct Solution { long a,b; char x; char y; }; // 3 4 5 6 // a c g o Solution solutions[] = { {3,4,'a','c'}, {4,5,'c','g'}, {5,6,'g','o'} }; int main() { std::ios_base::sync_with_stdio(0); long n,x = 0,y = 0; long* bt[2] = {&y, &x}; std::cin >> n; std::string bits; std::cin >> bits; for (char c : bits) ++(*bt[c-'0']); std::string s = "NIE"; for (auto sol : solutions) { auto[xx, yy, ok] = cramer(sol.a, sol.b, 8-sol.a, 8-sol.b, x, y); if (ok && xx >= 0 && yy >= 0) { s = std::string(xx, sol.x) + std::string(yy, sol.y); break; } } std::cout << s; 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 | #include <iostream> #include <utility> #include <tuple> std::tuple<long, long, bool> cramer(long a, long b, long c, long d, long e, long f) { long x1 = e*d-b*f; long x2 = a*d-b*c; if (x1%x2 != 0) return {0,0,false}; long y1 = a*f-e*c; long y2 = a*d-b*c; if (y1%y2 != 0) return {0,0,false}; return {x1/x2, y1/y2, true}; } struct Solution { long a,b; char x; char y; }; // 3 4 5 6 // a c g o Solution solutions[] = { {3,4,'a','c'}, {4,5,'c','g'}, {5,6,'g','o'} }; int main() { std::ios_base::sync_with_stdio(0); long n,x = 0,y = 0; long* bt[2] = {&y, &x}; std::cin >> n; std::string bits; std::cin >> bits; for (char c : bits) ++(*bt[c-'0']); std::string s = "NIE"; for (auto sol : solutions) { auto[xx, yy, ok] = cramer(sol.a, sol.b, 8-sol.a, 8-sol.b, x, y); if (ok && xx >= 0 && yy >= 0) { s = std::string(xx, sol.x) + std::string(yy, sol.y); break; } } std::cout << s; return 0; } |