Problem Description
屌丝
WP
的好基友
CZ
又被妖鬼给抓走了(
CZ
啊,
CZ….
怎么说你好呢
…
.
吃着锅里想着碗里),为了求出
CZ
,他只好去求高富帅
RQ, RQ
给
WP
出了到题目说只要你能解决这道题目,他就答应帮屌丝
WP
去解救好基友
CZ
。题目描述如下:
给你一个字符串s,长度小于1000,让你找出该字符串所包含的所有子串"cRazY" 或者"CraZy",并将找出的子串的大写字母变成小写字母,小写字母变成大写字母,然后输出该字符串。
“好基友,一被子” 你作为WP的好基友,能帮他解决这个问题吗?
给你一个字符串s,长度小于1000,让你找出该字符串所包含的所有子串"cRazY" 或者"CraZy",并将找出的子串的大写字母变成小写字母,小写字母变成大写字母,然后输出该字符串。
“好基友,一被子” 你作为WP的好基友,能帮他解决这个问题吗?
Input
第
1
行是一个整数
T
,表示测试数据的个数(
1<=T<=10
)。接下来有
T
组测试数据。
每组测试数据包括包括一个字符串s
Output
输出
T
行,表示转换后的字符串
Example Input
2 abjbjhcRazYdcRazYCraZy bbbnnnbbn
Example Output
abjbjhCrAZydCrAZycRAzYbbbnnnbbn
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n = in.nextInt(); while(n-->0){ String s1 = "cRazY"; String s2 = "CraZy"; String news1="CrAZy";//目标串1 String news2="cRAzY";//目标串2 String t = in.next(); System.out.println(replace(t,s1,news1,s2,news2)); } } public static String replace(String t,String s1,String news1,String s2,String news2){ t = t.replace(s1, news1); t = t.replace(s2, news2); return t; } }