daily pastebin goal
44%
SHARE
TWEET

Logical Problem Solution

Rajkumar_cs Oct 17th, 2017 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include < bits / stdc++.h >
  2.   using namespace std;
  3.  
  4. int main() {
  5.   string key[] = {
  6.     "1234567890",
  7.     "qwertyuiop",
  8.     "asdfghjkl",
  9.     "zxcvbnm"
  10.   };
  11.   string num[] = {
  12.     "!@#$%^&()",
  13.     "?~|R_-+*/="
  14.   };
  15.   string str;
  16.   getline(cin >> ws, str);
  17.   int len = str.length(), curX = 1, page1 = 1, page2 = 0, p1 = 0, p2 = 0, secX, secY, flag = 0, i, j, tempX, tempY, time = 0;
  18.   for (i = 0; i < len; i++) {
  19.     flag = 0;
  20.     p1 = 0;
  21.     p2 = 0;
  22.     for (j = 0; j < 4; j++) {
  23.       int t = key[j].find(str[i]);
  24.       if (t >= 0) {
  25.         flag = 1;
  26.         tempX = j + 1;
  27.         tempY = t + 1;
  28.         p1 = 1;
  29.         break;
  30.       }
  31.     }
  32.     if (!flag) {
  33.       for (j = 0; j < 2; j++) {
  34.         int t = num[j].find(str[i]);
  35.         if (t >= 0) {
  36.  
  37.           tempX = j + 1;
  38.           tempY = t + 1;
  39.           p2 = 1;
  40.           break;
  41.         }
  42.       }
  43.     }
  44.     if (p1) {
  45.       if (page1 == 0) {
  46.         time++;
  47.         if (tempX != 1)
  48.           time++;
  49.  
  50.         time += tempY - 1;
  51.       } else {
  52.         if (tempX != curX) {
  53.           time += tempY;
  54.  
  55.         }
  56.  
  57.       }
  58.  
  59.       curX = tempX;
  60.  
  61.       page1 = 1;
  62.       page2 = 0;
  63.     } else {
  64.       if (page2 == 0) {
  65.         time++;
  66.         if (tempX == 2)
  67.           time++;
  68.  
  69.         time += tempY - 1;
  70.       } else {
  71.         if (tempX != curX) {
  72.           time += tempY;
  73.  
  74.         }
  75.       }
  76.  
  77.       curX = tempX;
  78.  
  79.       page2 = 1;
  80.       page1 = 0;
  81.     }
  82.   }
  83.   cout << time;
  84.   return 0;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top