救基友记2

来源:互联网 发布:delphi 数据库 编辑:程序博客网 时间:2024/04/28 12:30

救基友记2

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

   屌丝WP的好基友CZ又被妖鬼给抓走了(CZ啊,CZ….怎么说你好呢.吃着锅里想着碗里),为了求出CZ,他只好去求高富帅RQ, RQWP出了到题目说只要你能解决这道题目,他就答应帮屌丝WP去解救好基友CZ。题目描述如下:
  给你一个字符串s,长度小于1000,让你找出该字符串所包含的所有子串"cRazY" 或者"CraZy",并将找出的子串的大写字母变成小写字母,小写字母变成大写字母,然后输出该字符串。
  “好基友,一被子” 你作为WP的好基友,能帮他解决这个问题吗?

Input

 1行是一个整数T,表示测试数据的个数(1<=T<=10)。接下来有T组测试数据。

每组测试数据包括包括一个字符串s

Output

 输出T行,表示转换后的字符串 

Example Input

2abjbjhcRazYdcRazYCraZybbbnnnbbn

Example Output

abjbjhCrAZydCrAZycRAzYbbbnnnbbn
//字符串的替换import java.text.ParseException;import java.util.Scanner;public class Main {public static void main(String[] args) throws ParseException {Scanner sc = new Scanner(System.in);int count = sc.nextInt();String str1="cRazY";//被替换串1String str2="CraZy";//被替换串2String newstr1="CrAZy";//目标串1String newstr2="cRAzY";//目标串2for (int i = 0; i < count; i++) {String str=sc.next();System.out.println(replace(str,str1,newstr1,str2,newstr2));}sc.close();}public static String replace(String str,String str1,String newStr1,String str2,String newStr2){str=str.replace(str1, newStr1);str=str.replace(str2, newStr2);return str;}}


0 0
原创粉丝点击