T1 note 数组开小 菜的真实 60分

题目大意:

一个字符串 分成若干段 使每段内都没有重复的字符 求最少的段数

思路:

可以贪心

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<vector>
 8 #include<queue>
 9 #define inf 2139062143
10 #define ll long long
11 #define MAXN 601010
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 char ch[MAXN];
21 int n,ans,hsh[30];
22 int main()
23 {
24     freopen("note.in","r",stdin);
25     freopen("note.out","w",stdout);
26     scanf("%s",ch+1);
27     int n=strlen(ch+1);
28     for(int i=1;i<=n;i++)
29     {
30         if(hsh[ch[i]-'a']) {memset(hsh,0,sizeof(hsh));ans++;}
31         hsh[ch[i]-'a']=1;
32     }
33     printf("%d",ans+1);
34 }
View Code

相关文章:

  • 2021-10-08
  • 2021-08-09
  • 2020-11-04
  • 2018-10-28
  • 2021-08-08
  • 2021-10-17
  • 2021-06-27
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2019-03-19
  • 2021-12-25
  • 2021-07-21
  • 2022-12-23
相关资源
相似解决方案