本题考查分支结构和字符串处理。
基本思路是遍历字符串的每个字符,如果遇到需要过滤的字符则跳过,否则输出该字符。
读入字符串数量
循环处理每个字符串
遍历字符串中的每个字符
如果字符是 '1', 'i', 'l', 'I' 则跳过,否则输出
/*
Auther:MingDynasty
Problem:https://www.luogu.com.cn/problem/P12527
*/
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>a;
while(a--){
string k;
cin>>k;
for(int i=0;i<k.size();i++){
if(k[i]=='1'||k[i]=='i'||k[i]=='l'||k[i]=='I') continue;
cout<<k[i];
}
cout<<'\n';
}
return 0;
}
代码说明:
cin.tie(0)->sync_with_stdio(0) 加速输入输出时间复杂度:O(n),其中 n 是所有字符串的总长度
空间复杂度:O(1),除了存储输入外没有使用额外空间