专栏文章
P12714 [Algo Beat Contest 002 A] A to Z题解
P12714题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mip4jvic
- 此快照首次捕获于
- 2025/12/03 06:03 3 个月前
- 此快照最后确认于
- 2025/12/03 06:03 3 个月前
题面
给了 个字符串。问有几个字符串的每个字符都不相同。
解题思路
先开一个
t 数组,用来保存字符串 a 中每个字符出现的次数。
遍历 a ,如果 a[i] 出现过,不累加。否则把 t[ a[ i ] - 'a' ] 置为1。如果遍历完以后都符合条件,累加。
AC代码
CPP#include<bits/stdc++.h>
using namespace std;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
int s=0;
int T;
cin>>T;
while(T--){
string a;
cin>>a;
int t[30]={0};//桶数组
bool flag=1;//标记
for(int i=0;i<a.size();i++){
if(t[a[i]-'a']){//出现过
flag=0;break;
}
t[a[i]-'a']=1;
}
if(flag) s++;//累加答案
}
cout<<s;
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...