Advertisement
Emiliatan

e156 - 2

Apr 13th, 2019
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. /* e156 - 2        */
  2. /* AC (3ms, 304KB) */
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. class A;
  8.  
  9. unsigned int n;
  10. A *arr[2];
  11.  
  12. class A
  13. {
  14.     public:
  15.         virtual unsigned int Sum(unsigned int n)
  16.         {
  17.             return 0;
  18.         }
  19. };
  20.  
  21. class B: public A
  22. {
  23.     public:
  24.         virtual unsigned int Sum(unsigned int n)
  25.         {
  26.             return arr[!!n] -> Sum(n - 1) + n;
  27.         }
  28. };
  29.  
  30. unsigned int Sum_Solution(unsigned int n)
  31. {
  32.     A a;
  33.     B b;
  34.     arr[0] = &a;
  35.     arr[1] = &b;
  36.  
  37.     unsigned int value = arr[1] -> Sum(n);
  38.  
  39.     return value;
  40. }
  41.  
  42. int main()
  43. {
  44.     scanf("%u", &n);
  45.     printf("%u", Sum_Solution(n));
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement