zoukankan      html  css  js  c++  java
  • hdu 3793 水题

    判断一个环形的字符串是否对称,其实只需要一一尝试以每一个字符作为中间位置即可。

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

    const int MAXN = 105;
    char str[MAXN];

    void work();
    int main() {
    #ifndef ONLINE_JUDGE
    freopen(
    "data.in", "r", stdin);
    #endif
    work();
    return 0;
    }

    void work() {
    int len;
    bool flag;
    while (scanf("%s", str) != EOF) {
    if (strcmp(str, "#") == 0) {
    break;
    }
    len
    = strlen(str);
    int j;
    for (j = 0; j < len; j++) {
    flag
    = true;
    for (int i = 0; i < len / 2; i++) {
    if (str[(i + j) % len] != str[(len - i - 1 + j) % len]) {
    flag
    = false;
    break;
    }
    }
    if (flag) {
    printf(
    "YES %d\n", (len / 2 + j) % len);
    break;
    }
    }
    if (j == len) {
    puts(
    "NO");
    }
    }
    }

      

  • 相关阅读:
    记坑
    常用模板
    ACM-东北赛划水记
    jzoj 4178游戏
    JZOI 4163
    jzoj 4146踩气球
    jzoj 5589. 缩点
    jzoj 5588 %%%
    jzoj 5571 ffs
    BJOI 2017 Kakuro
  • 原文地址:https://www.cnblogs.com/moonbay/p/2173803.html
Copyright © 2011-2022 走看看