zoukankan      html  css  js  c++  java
  • 九度oj 1530 最长不重复子串

    原题链接:http://ac.jobdu.com/problem.php?pid=1530

    字符串简单题,看似O(n^2)的复杂度10000的数据量会tle,其实最长不重复子串不超过26个嘛。。。

    如下:

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 using std::max;
     7 const int Max_N = 10010;
     8 int vis[26];
     9 char buf[Max_N];
    10 void solve(){
    11     int i, j, ans = 0, n = strlen(buf);
    12     for (i = 0; i < n - 1; i++){
    13         int t = 1;
    14         memset(vis, 0, sizeof(vis));
    15         vis[buf[i] - 'a'] = 1;
    16         for (j = i + 1; j < n; j++){
    17             if (!vis[buf[j] - 'a']){
    18                 vis[buf[j] - 'a'] = 1;
    19                 t++;
    20             } else {
    21                 break;
    22             }
    23         }
    24         ans = max(ans, t);
    25     }
    26     printf("%d
    ", ans);
    27 }
    28 int main(){
    29 #ifdef LOCAL
    30     freopen("in.txt", "r", stdin);
    31     freopen("out.txt", "w+", stdout);
    32 #endif
    33     while (~scanf("%s", buf)) solve();
    34     return 0;
    35 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    UVA 10066 The Twin Towers
    UVA 10192 Vacation
    hdu 5018 Revenge of Fibonacci
    hdu 5108 Alexandra and Prime Numbers
    UVA 10252
    UVA 10405最长公共子序列
    数塔
    hdu 2602
    面向对象(五)
    面向对象(三)
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4477615.html
Copyright © 2011-2022 走看看