Advertisement
DMG

GPS (Bihac - skolsko takmicenje 2008)

DMG
Feb 24th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int pomjereno (char a, char b)
  6. {
  7.     int a1, a2, a3, a4;
  8.     int c[10][10];
  9.    
  10.     int d = 65;
  11.      
  12.       for (int i=0; i<5; i++)
  13.       for (int j=0; j<6; j++)
  14.           {
  15.                c[i][j] = d;
  16.                d = d + 1;
  17.           }
  18.      
  19.       c[4][2]= ' ';
  20.       c[4][3]= '-';
  21.       c[4][4]= '.';
  22.       c[4][5]= 'e';
  23.    
  24.     for(int i=0; i<5; i++)
  25.     for(int j=0; j<6; j++)
  26.     if (c[i][j] == a)
  27.       { a1 = i;
  28.        a2 = j;}
  29.        
  30.     for(int i=0; i<5; i++)
  31.     for(int j=0; j<6; j++)
  32.     if (c[i][j] == b)
  33.     {   a3 = i;
  34.        a4 = j;}
  35.        
  36.     int s = 0;
  37.     if (a1-a3 < 0)
  38.        s = s + (a1-a3)*(-1);
  39.     else s = s + a1-a3;
  40.    
  41.     if (a2-a4 < 0)
  42.        s = s + (a2-a4)*(-1);
  43.     else s = s + a2-a4;
  44.    
  45.     return s;
  46. }
  47.  
  48. main()
  49. {
  50.       char a[10][10];
  51.       string ab;
  52.      
  53.       getline(cin, ab);
  54.      
  55.       /* int s = 65;
  56.      
  57.       for (int i=0; i<5; i++)
  58.       for (int j=0; j<6; j++)
  59.           {
  60.                a[i][j] = s;
  61.                s = s + 1;
  62.           }
  63.      
  64.       a[4][2]= ' ';
  65.       a[4][3]= '-';
  66.       a[4][4]= '.';
  67.       a[4][5]= 'e';
  68.      
  69.       for (int i=0; i<5; i++)
  70.       {
  71.           for (int j=0; j<6; j++)
  72.           cout << a[i][j] << " ";
  73.          cout << endl;
  74.       }  */
  75.      
  76.       int d = 0;
  77.      
  78.       d = pomjereno('A', ab[0]);
  79.       for (int i=0; i<ab.length()-1; i++)
  80.       d = d + pomjereno(ab[i], ab[i+1]);
  81.      
  82.       d = d + pomjereno(ab[ab.length()-1], 'e');
  83.      
  84.       cout << d << endl;
  85.      
  86.       system ("PAUSE");
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement