Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- using namespace std;
- unordered_map< char, int > order;
- const int alphabet_size = 26;
- int main() {
- int i;
- char lastCh, ch, cnt;
- for ( i = 0; i < alphabet_size; i++ ) {
- cin >> ch;
- order[ ch ] = i;
- }
- // cin.ignore();
- cin >> lastCh >> ch;
- cnt = 1;
- while ( ch != '\n' ) {
- if ( order[ ch ] <= order[ lastCh ] )
- cnt++;
- lastCh = ch;
- cin >> ch;
- }
- cout << cnt << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement