Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     unsigned long long int input[2], calc_square;
  11.  
  12.     while(scanf("\n%llu %llu", input[0], input[1]), input[0] || input[1])
  13.     {
  14.         printf("%llu %llu\n", input[0], input[1]);
  15.  
  16.         uint32_t distance_seq = 0;
  17.  
  18.         if(input[0] == input[1])
  19.         {
  20.             distance_seq += 2;
  21.             break;
  22.         }
  23.         else
  24.         {
  25.             for(int i = 0; i < 2; i++)
  26.             {
  27.                 char temp[100];
  28.                 vector<unsigned long long int> arr;
  29.  
  30.                 arr.push_back(input[i]);
  31.                
  32.                 for(int z = 0; ; z++)
  33.                 {
  34.                     calc_square = 0;
  35.  
  36.                     sprintf(temp, "%llu", arr[i]);
  37.  
  38.                     for(int x = 0; x < strlen(temp); x++)
  39.                     {
  40.                         calc_square += (temp[x] - 48) * (temp[x] - 48);
  41.                     }
  42.  
  43.                     // search if already exist in our array
  44.                     vector<unsigned long long int>::iterator it = find(arr.begin(), arr.end(), calc_square);
  45.  
  46.                     if(it != arr.end())
  47.                     {
  48.                         distance_seq += distance(arr.begin(), it);
  49.                         break;
  50.                     }
  51.                     else
  52.                     {
  53.                         arr.push_back(calc_square);
  54.                         continue;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.  
  60.         printf("%llu %llu %u\n", input[0], input[1], distance_seq);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement