1112. Stucked Keyboard (20)
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.
Now given a resulting string on screen, you are supposed to list all the possible stucked keys, and the original string.
Notice that there might be some characters that are typed repeatedly. The stucked key will always repeat output for a fixed k times whenever it is pressed. For example, when k=3, from the string "thiiis iiisss a teeeeeest" we know that the keys "i" and "e" might be stucked, but "s" is not even though it appears repeatedly sometimes. The original string could be "this isss a teest".
Input Specification:
Each input file contains one test case. For each case, the 1st line gives a positive integer k ( 1<k<=100 ) which is the output repeating times of a stucked key. The 2nd line contains the resulting string on screen, which consists of no more than 1000 characters from {a-z}, {0-9} and "_". It is guaranteed that the string is non-empty.
Output Specification:
For each test case, print in one line the possible stucked keys, in the order of being detected. Make sure that each key is printed once only. Then in the next line print the original string. It is guaranteed that there is at least one stucked key.
Sample Input:3 caseee1__thiiis_iiisss_a_teeeeeestSample Output:
ei case1__this_isss_a_teest
我也说不清这属于考什么的。字符串处理?感觉我的逻辑判断有点麻烦。应该有更简单的判断,随后再看。
#include<iostream> #include<algorithm> #include<string.h> #include<string> #include<stdio.h> #include<queue> #include<set> #include<deque> using namespace std; int n; string s; int mark[257]={0}; int mark2[257]={0}; int path[256]; int p=0; void findyou() { int pp; int cnt=0; for(int i=0;i<s.size();) { //cout<<"I: "<<s[i]<<endl; if(i==s.size()-1) { cnt++;break; } for(int j=i+1;j<s.size();j++) { cnt++; //cout<<"JJ: "<<s[j]<<endl;; if(s[i]!=s[j]) { mark[s[i]]=1; //cout<<"MARK"<<' '<<s[i]<<endl; i=j; cnt=0; break; } if(cnt==n-1) { i=j+1; cnt=0; break; } if(j+1==s.size()) { cnt=1; i=j+1; break; } } } if(cnt!=0) mark[s[s.size()-1]]=1; } int main() { cin>>n; getchar(); getline(cin,s); findyou(); for(int i=0;i<s.size();i++) if(mark[s[i]]==0) { for(int j=0;j<n-1;j++) { s.erase(i,1); // cout<<s<<endl; } } //set<char> S; vector<char> S; for(int i=0;i<s.size();i++) if(mark2[s[i]]==0&&mark[s[i]]==0) { S.push_back(s[i]); mark2[s[i]]=1; } vector<char>::iterator it; ///it=unique(S.begin(),S.end()); // if(it!=S.end()) S.erase(it,S.end()); for(it=S.begin();it!=S.end();it++) cout<<*it; cout<<endl; cout<<s; return 0; }