度度熊找子串

题目链接: http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3364&konwledgeId=40

解题思路: 这种题目是真的没意思。

 1 #include 
 2 using namespace std;
 3 
 4 const int MAXN = 100005;
 5 typedef long long LL;
 6 char s[MAXN];
 7 int ans[256];
 8 int main()
 9 {
10 #ifndef ONLINE_JUDGE
11     freopen("test.txt","r",stdin);
12 #endif // ONLINE_JUDGE
13     int Case;
14     // scanf("%d",&Case);
15     //scanf("%s",s);
16     //printf("%d\n",strlen(s));
17     memset(ans,0,sizeof(ans));
18     int cnt=0;
19     char ch;
20     char tmp;
21     for (int i=0;(tmp=getchar())!='\n';++i)
22     {
23         if (i==0) cnt=1,ch=tmp;
24         else if (tmp==ch) ++cnt;
25         else {ans[ch]=max(ans[ch],cnt);cnt=1;ch=tmp;}
26     }
27     ans[ch]=max(ans[ch],cnt);
28     int res=0;
29     for (int i='a';i<='z';++i) res+=ans[i];
30     printf("%d\n",res);
31     return 0;
32 }

 

转载于:https://www.cnblogs.com/djingjing/p/8902331.html

你可能感兴趣的:(度度熊找子串)