zoukankan      html  css  js  c++  java
  • hdu 3788 字符串

    题目很简单,可是打了一个小时,这种题目真是悲剧啊

    /*
    * hdu3788/win.cpp
    * Created on: 2011-9-6
    * Author : ben
    */
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cmath>
    #include
    <algorithm>
    using namespace std;

    const int MAXN = 1010;

    bool judge(char *s, int len) {
    if (len < 3) {
    return false;
    }
    if (len == 3) {
    return (s[0] == 'z' && s[1] == 'o' && s[2] == 'j');
    }
    int ii = 0;
    while (s[ii] == s[len - 1 - ii] && s[ii] == 'o') {
    ii
    ++;
    }
    if (len - 2 * ii == 3) {
    return judge(&s[ii], len - 2 * ii);
    }
    char tempstr[MAXN];
    int a = 0, tlen;
    while (s[a] == 'o' && a < len) {
    a
    ++;
    }
    if (a > len - 3) {
    return false;
    }
    for (tlen = 0; tlen < a; tlen++) {
    tempstr[tlen]
    = s[tlen];
    }
    if (s[tlen] != 'z') {
    return false;
    }
    tempstr[tlen]
    = 'z';
    if (s[++tlen] != 'o') {
    return false;
    }
    for (; tlen < len - a - 1; tlen++) {
    tempstr[tlen]
    = s[tlen + 1];
    }
    tempstr[tlen]
    = '\0';
    for (int t = tlen + 1; t < len; t++) {
    if (s[t] != 'o') {
    return false;
    }
    }
    return judge(tempstr, tlen);
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen(
    "data.in", "r", stdin);
    #endif
    char str[MAXN];
    while (scanf("%s", str) == 1) {
    if (judge(str, strlen(str))) {
    puts(
    "Accepted");
    }
    else {
    puts(
    "Wrong Answer");
    }
    }
    return 0;
    }
  • 相关阅读:
    HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
    字典树 HDU 1075 What Are You Talking About
    字典树 HDU 1251 统计难题
    最小生成树prim算法 POJ2031
    POJ 1287 Networking 最小生成树
    次小生成树 POJ 2728
    最短路N题Tram SPFA
    poj2236 并查集
    POJ 1611并查集
    Number Sequence
  • 原文地址:https://www.cnblogs.com/moonbay/p/2169479.html
Copyright © 2011-2022 走看看