zoukankan      html  css  js  c++  java
  • 亲和串

     1 #include<stdio.h> //亲和串的c语言代码
     2 #include<string.h>
     3 char s1[200020],s2[100010],s3[200020];
     4 int main()
     5 {
     6     int  l1, l2;
     7     while(gets(s1))
     8     {
     9         gets(s2);
    10         l1 = strlen(s1);
    11         l2 = strlen(s2);
    12         if(l1 < l2)
    13         {
    14             printf("no
    ");
    15         }
    16         else
    17         {
    18             strcpy(s3,s1);
    19             strcat(s1,s3);
    20             if(strstr(s1,s2))
    21                 printf("yes
    ");
    22             else
    23                 printf("no
    ");
    24         }
    25     }
    26     return 0;
    27 }

    Description

    人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。 
    亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。 
     

    Input

    本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。 
     

    Output

    如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。 
     

    Sample Input

    AABCD
    CDAA
    ASD
    ASDF
     

    Sample Output

    yes
    no
     
     
     
     
     
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <cstring>
    using namespace std;
    #define INF 0xfffffff
    #define maxn 120000
    
    bool Slove(char s1[],char s2[])
    {
        char s3[maxn];
    
        if( strlen(s1) <  strlen(s2) )
            return false;
    
        strcpy(s3,s1);
        strcat(s3,s1);
    
        return strstr(s3,s2);
    }
    
    int main()
    {
        char s1[maxn], s2[maxn];
    
        while(cin >> s1)
        {
            cin >> s2;
    
            if( Slove(s1,s2) )
                cout << "yes" << endl;
            else
                cout << "no" <<endl;
        }
        return 0;
    }
  • 相关阅读:
    表达式树
    二叉查找树
    二叉树的先中后序遍历
    利用树的先序和后序遍历打印 os 中的目录树
    栈应用(中缀表达式转后缀表达式并计算后缀表达式的值)
    C语言的运算符的优先级与结合性+ASCII表
    算法运行时间中的对数
    c++ primer 第三章 标准库类型
    C++ premier 中文版 学习笔记(第五章 表达式)
    使用applescript脚本方式以管理员权限运行
  • 原文地址:https://www.cnblogs.com/yishilin/p/4237222.html
Copyright © 2011-2022 走看看