当前位置:网站首页>3381. Mobile keyboard (Tsinghua University postgraduate entrance examination machine test question)

3381. Mobile keyboard (Tsinghua University postgraduate entrance examination machine test question)

2022-07-27 04:05:00 Ray.C.L

 Insert picture description here

Ideas : simulation

Code :

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int numbers[] = {
    
    2, 2, 2, 3, 3, 3, 4, 4, 4,
    5, 5, 5, 6, 6, 6, 7, 7, 7,
    7, 8, 8, 8, 9, 9, 9, 9
};

int main()
{
    
    string s;
    while(cin >> s){
    
        int last = -1, res = 0;
        for(auto c : s){
    
            int  t = c - 'a';
            for(int i = t; i >= 0; i --)
                if(numbers[t] == numbers[i])
                    res ++;
                else
                    break;
                    
            if(numbers[t] == numbers[last]) res +=2;
            last = t;
            
        }
        
        printf("%d\n", res);
    }
    
    return 0;
}
原网站

版权声明
本文为[Ray.C.L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207270236504688.html