然而沼跃鱼早就看穿了一切
Time Limit: 1 Sec Memory Limit: 256 MB
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出
输出包含多行,为输入按照描述中变换的结果。
1 2 3
| The Marshtomp has seen it all before. marshTomp is beaten by fjxmlhx! AmarshtompB
|
Sample Output
1 2 3
| The fjxmlhx has seen it all before. fjxmlhx is beaten by fjxmlhx! AfjxmlhxB
|
题解
注意不等数量的替换用两个下标记录很轻松和先换成小写要还原成大写。
## AC code:(不包含输入类)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); while(sc.hasNext()){ String s=sc.nextLine(); String temp=s.toLowerCase(); temp=temp.replace("marshtomp", "fjxmlhx"); StringBuilder sb=new StringBuilder(); int i=0; int j=0; while(i<s.length()){ if(s.charAt(i)==temp.charAt(j)){ sb.append(s.charAt(i)); i++; j++; } else{ if(s.charAt(i)-'A'+'a'==temp.charAt(j)){ sb.append(s.charAt(i)); i++; j++; } else{ i=i+9; j=j+7; sb.append("fjxmlhx"); } } } System.out.println(sb.toString()); } } }
|