// mc3a.cpp : Defines the entry point for the console application. // #include #include #include using namespace std; long long a, b, n; char keyboard[20][20] = { {'Q','W','E','R','T','Y','U','I','O','P'}, {'A','S','D','F','G','H','J','K','L', 0 }, {'Z','X','C','V','B','N','M', 0 , 0 , 0 } }; int countDistance(char x, char y) { int i, j, poz1x, poz1y, poz2x, poz2y; for (i = 0; i < 3; i++) { for (j = 0; j < 10; j++) { if (keyboard[i][j] == x) { poz1x = i; poz1y = j; } if (keyboard[i][j] == y) { poz2x = i; poz2y = j; } } } return abs(poz1x - poz2x) + abs(poz1y - poz2y); } char str[10001]; int main() { char pozLeft, pozRight; cin.getline(str, 10000); int p = strlen(str); int sum = 0; pozLeft = 'F'; pozRight = 'J'; for (int i = 0; i < p; i++) { int d1 = countDistance(pozLeft, str[i]); int d2 = countDistance(pozRight, str[i]); if (d1 < d2) { sum += d1; pozLeft = str[i]; } else { sum += d2; pozRight = str[i]; } } cout << sum; }