Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Result {
- public:
- uint64_t val;
- Result(uint64_t v)
- {
- val = v;
- }
- uint64_t ret()
- {
- return val;
- }
- };
- void bar(uint64_t a, uint64_t b)
- {
- if (a == 0) {
- throw Result(b + 1);
- } else if (a > 0 && b == 0) {
- try {
- bar(a - 1, b);
- } catch (Result t) {
- throw t;
- }
- } else if (a > 0 && b > 0) {
- try {
- bar(a, b - 1);
- } catch (Result t){
- try {
- bar(a - 1, t.ret());
- } catch (Result t) {
- throw t;
- }
- }
- }
- }
- int main()
- {
- uint64_t a, b;
- while (std::cin >> a >> b) {
- try {
- bar(a, b);
- } catch(Result t) {
- std::cout << t.ret() << std::endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement