Advertisement
Guest User

c++ is dumb

a guest
Jul 19th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. using namespace std;
  4.  
  5. unordered_map< char, int > order;
  6. const int alphabet_size = 26;
  7.  
  8. int main() {
  9.   int i;
  10.   char lastCh, ch, cnt;
  11.  
  12.   for ( i = 0; i < alphabet_size; i++ ) {
  13.     cin >> ch;
  14.     order[ ch ] = i;
  15.   }
  16.   // cin.ignore();
  17.   cin >> lastCh >> ch;
  18.   cnt = 1;
  19.   while ( ch != '\n' ) {
  20.     if ( order[ ch ] <= order[ lastCh ] )
  21.       cnt++;
  22.     lastCh = ch;
  23.     cin >> ch;
  24.   }
  25.  
  26.   cout << cnt << '\n';
  27.  
  28.   return 0;
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement