codeforce A. Many Equal Substrings

 

http://codeforces.com/contest/1029/problem/A

 

嗳,简单的题做起来是真的舒服qwq

 

 1  public static void main(String[] args) {
 2         Scanner io=new Scanner(System.in);
 3         int n=io.nextInt(),k=io.nextInt();
 4         String str=io.nextLine();
 5         while (str.length()==0)str=io.nextLine();
 6 
 7         String ans="";
 8         for (int len=str.length()-1;len>=0;len--){
 9             if (len==0){
10                 for (int i = 0; i < k; i++) ans+=str;
11                 System.out.println(ans);
12                 return;
13             }
14             String s1=str.substring(0,len);
15             String s2=str.substring(str.length()-len);
16             if (s1.equals(s2)){
17                 ans+=str;
18                 s1=str.substring(len);
19                 for (int i = 0; i < k - 1; i++) ans+=s1;
20                 System.out.println(ans);
21                 return;
22             }
23         }
24     }

 

posted @ 2019-10-20 23:46  dodoBehind  阅读(172)  评论(0编辑  收藏  举报