zoukankan      html  css  js  c++  java
  • hihocoder 1061.Beautiful String

    题目链接:http://hihocoder.com/problemset/problem/1061

    题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings的子串:连续递增且数量相等的字母。

      照着题目分析翻译的代码。。。

      分析得很到位呢,大赞 ^_^

      http://hihocoder.com/discuss/question/2083

      hiho的题目其实挺好的,有专题,有分析,有代码 & 思路参考。。。

      想想出来工作那么久,浮躁的心啊,一个多快两个月没碰啦,得捡回来呢~~~继续ACM哇,为T-shirt fighting !

      

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int maxn = 1024*1024*10;   // 10MB的字节(1024字节=1KB,1024K=1M)
     8 char str[maxn], s[maxn];
     9 int cnt[maxn];
    10 
    11 int main()
    12 {
    13     #ifndef ONLINE_JUDGE
    14         freopen("in.txt", "r", stdin);
    15     #endif // ONLINE_JUDGE
    16 
    17     int n, cas;
    18     while (scanf("%d", &cas) != EOF) {
    19       while (cas--) {
    20         scanf("%d", &n);
    21         scanf("%s", str);
    22         memset(cnt, 0, sizeof(cnt));
    23         int num = 0;
    24         int c = 1;
    25         for (int i = 0; i < n; i++) {
    26             if (str[i] == str[i+1]) {
    27                 c++;
    28             }
    29             else {
    30                 s[num] = str[i];
    31                 cnt[num++] = c;
    32                 c = 1;
    33             }
    34         }
    35 
    36         bool flag = false;
    37         for (int i = 1; i < num; i++) {
    38             if (s[i-1]+1 == s[i] && s[i]+1 == s[i+1] && cnt[i-1] >= cnt[i] && cnt[i] <= cnt[i+1]) {
    39                 flag = true;
    40                 break;
    41             }
    42         }
    43         printf("%s
    ", flag ? "YES" : "NO");
    44       }
    45     }
    46     return 0;
    47 }

      

  • 相关阅读:
    [LeetCode] Word Break 解题思路
    [LeetCode] Longest Valid Parentheses 解题思路
    [LeetCode] Largest Rectangle in Histogram 解题思路
    新博客
    正在学习的Angularjs包裹的插件
    Markdown
    Markdown 基础
    Angular docs
    npm-link
    webpack-hot-middleware 用于 livereload
  • 原文地址:https://www.cnblogs.com/windysai/p/5043942.html
Copyright © 2011-2022 走看看