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;
    }
  • 相关阅读:
    SDOI2008]仪仗队
    洛谷P1414 又是毕业季II
    P3865 【模板】ST表
    [HAOI2007]理想的正方形
    noip 2011 选择客栈
    [AHOI2009]中国象棋
    洛谷P3387 【模板】缩点
    [SCOI2005]最大子矩阵
    [CQOI2009]叶子的染色
    LibreOJ #116. 有源汇有上下界最大流
  • 原文地址:https://www.cnblogs.com/moonbay/p/2169479.html
Copyright © 2011-2022 走看看