1033 旧键盘打字
str1是坏掉的键盘,str2是本要输出的字符串
考虑到str2会很长的情况下,就只循环一次str2,先是用的for循环,发现str2的长度在erase的过程中会变短,就用while(!str2.empty())循环,str2[count]代表当前字符,若当前字符有被去掉,去掉后count不变,继续判断下一个字符,若没有去,则count++继续下一个判断。
#include#include // 补充 npos 是一个常数,用来表示不存在的位置 using namespace std; string remove(string str1,string str2) { //先判断是否有"+" bool flag=false; int count=0; if((str1.find('+',0) != string::npos)) { flag=true; } bool iden=false; while(!str2.empty()) { if(count==str2.size()) break; if(flag==true) { if((str2[count]>='A'&&str2[count]<='Z')) { str2.erase(count,1); iden=true; } else{ for(int j=0;j 这个代码虽然AC了,但是最后一个测试点用了100多ms,过于长了
我在牛客网这道题的下面找到了一个大佬的代码
这道题的下面第一个
侵删
附上代码:#include#include int main(){ char A[123] = {0}, ch; while ((ch = getchar()) != 'n') A[ch]++; while ((ch = getchar()) != 'n') if ((isupper(ch) && A[43]) || A[toupper(ch)]) continue; else putchar(ch); return 0; } 最后一个测试点也保持在10ms以内
今天又学到了



