Java sdut acm 2271 Eddy的难题
2017-04-14 16:29
295 查看
题目链接:点击打开链接
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
<p align="\"LEFT\"" 0cm;="" widows:="" 2;="" orphans:="" 2\"="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 3px;">人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何 判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。
亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。
本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。
如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。
glt
代码实现:
法二:
package hhh;
import java.text.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws ParseException {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
String str1 = input.next();
String str2 = input.next();
if(str1.length() < str2.length())
System.out.println("no");
else{
StringBuffer str3 = new StringBuffer(str1);
StringBuffer str4 = new StringBuffer(str2);
str3.append(str1);
if(str3.toString().contains(str4))
System.out.println("yes");
else
System.out.println("no");
}
}
}
}
Eddy的难题
Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic
Problem Description
<p align="\"LEFT\"" 0cm;="" widows:="" 2;="" orphans:="" 2\"="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 3px;">人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何 判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。
Input
本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。
Output
如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。
Example Input
AABCD CDAA ASD ASDF
Example Output
yes no
Hint
Author
glt代码实现:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) throws ParseException { Scanner input = new Scanner(System.in); while(input.hasNext()){ String str1 = input.next(); String str2 = input.next(); if(isExist(str1, str2)) System.out.println("yes"); else System.out.println("no"); } } public static boolean isExist(String str1,String str2){ boolean flag = false; //构造缓冲区 StringBuffer buffer = new StringBuffer(str1); //移位的次数 int index = 0; //若原串就包含,则结束 //未包含,循环移位,在判断,直至还原为原串 do{ if(buffer.toString().contains(str2)){ flag = true; break; } else{ char ch = str1.charAt(index); buffer.deleteCharAt(0).append(ch); index++; } }while(index < str1.length()); return flag; } }
法二:
package hhh;
import java.text.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws ParseException {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
String str1 = input.next();
String str2 = input.next();
if(str1.length() < str2.length())
System.out.println("no");
else{
StringBuffer str3 = new StringBuffer(str1);
StringBuffer str4 = new StringBuffer(str2);
str3.append(str1);
if(str3.toString().contains(str4))
System.out.println("yes");
else
System.out.println("no");
}
}
}
}
相关文章推荐
- Java sdut adcm 2271 Eddy的难题
- sdut_java_Eddy的难题
- 杭电oj 2200 Eddy's AC难题 Java
- 计算长方体、四棱锥的表面积和体积(Java)acm.sdut
- 小学数学(Java)acm.sdut
- Java sdut acm 2178 链表的有序集合
- Java sdut acm 2714 下沉的船(字符串、链表)
- 笨蛋得难题 (来源:南阳理工大学ACM)java
- Java sdut ACM 2787 加密术
- Java sdut acm 2618 手机键盘
- Java sdut acm 2402 水杯
- Java-sdut-ACM 3870 判定Java源文件名称
- 分数加减法(Java)acm.sdut
- Java sdut acm 2253 分数加减法
- 高中数学?(Java)acm.sdut
- 时间日期格式转换(Java)acm.sdut
- 分数四则运算(Java)acm.sdut
- 正方形(Java)acm.sdut
- 多项式求和(Java)acm.sdut
- Java sdut acm 1916 字符串扩展