题解:P12714 [Algo Beat Contest 002 A] A to Z
题解:P12714 [Algo Beat Contest 002 A] A to Z
-
思路:将字符数组转换成每项在 \(1 \sim 26\) 之间的数组。
-
接下来用桶来查重即可,注意多测清空。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+10;
ll T,num[N],t[N],ans=0,temp;
string s;
int main(){
cin>>T;
temp=T;
while(T--){
cin>>s;
ll cnt=0; //多测清空
for(int i=0;i<s.size();i++) num[cnt++]=s[i]-'a'+1; //运用 ASCII 码表进行转换
for(int i=0;i<27;i++) t[i]=0; //数组手动清空
bool f=0;
for(int i=0;i<cnt;i++){
t[num[i]]++; //运用桶进行计数。实际上桶开到 27 就可以
if(t[num[i]]>1) f=1;
}
if(f) ans++;
}
cout<<temp-ans;
return 0;
}