Java练习 SDUT-2271_Eddy的难题

Eddy的难题

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem 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

···
import java.text.ParseException;
import java.util.*;

public class Main {
public static void main(String []args) throws ParseException
{
Scanner cin = new Scanner(System.in);
node a;
while(cin.hasNextLine())
{
a = new node(cin.nextLine(),cin.nextLine());
if(a.f()==true)
System.out.println("yes");
else
System.out.println("no");
}
cin.close();
}
}

class node
{
String s1,s2;
node(String s1,String s2)
{
this.s1 = s1;
this.s2 = s2;
}
boolean f()
{
int i;
StringBuffer a = new StringBuffer(s1);
i = 0;
while(i<s1.length())
{
if(a.toString().contains(s2))
return true;
char c;
c = s1.charAt(i);
a.deleteCharAt(0);
a.append(c);
i++;
}
return false;
}
}
···

猜你喜欢

转载自www.cnblogs.com/luoxiaoyi/p/10034248.html