AOJ : 2252 - koukyoukoukokukikou
問題概要
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2252
日本語の問題文なので省略です.
アルゴリズム
キーボードの左側の文字を全てプログラムに埋め込んでおきます.
あとは, 今打っているのがキーボードの左か右かを記憶するbool変数があれば解けます.
プログラム
int main(){ string s; string left = "qwertasdfgzxcvb"; while(cin>>s,s!="#"){ int now = -1; //0:left 1:right int cnt = 0; rep(i,s.length()){ int next = (left.find(s[i]) == string::npos); if(now != -1 && now != next){ cnt++; } now = next; } cout<<cnt<<endl; } }