2191救基友记2

救基友记2

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description
    屌丝 WP 的好基友 CZ 又被妖鬼给抓走了( CZ 啊, CZ…. 怎么说你好呢 . 吃着锅里想着碗里),为了求出 CZ ,他只好去求高富帅 RQ, RQ WP 出了到题目说只要你能解决这道题目,他就答应帮屌丝 WP 去解救好基友 CZ 。题目描述如下:
  给你一个字符串s,长度小于1000,让你找出该字符串所包含的所有子串"cRazY" 或者"CraZy",并将找出的子串的大写字母变成小写字母,小写字母变成大写字母,然后输出该字符串。
  “好基友,一被子” 你作为WP的好基友,能帮他解决这个问题吗?
Input
  1 行是一个整数 T ,表示测试数据的个数( 1<=T<=10 )。接下来有 T 组测试数据。

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

Output
  输出 T 行,表示转换后的字符串 
Example Input
2
abjbjhcRazYdcRazYCraZy
bbbnnnbbn
Example Output
abjbjhCrAZydCrAZycRAzY
bbbnnnbbn
import java.util.*;
public class Main {

	public static void main(String[] args) {
	 Scanner cin = new Scanner(System.in);
	 int n = cin.nextInt();
	 for(int i = 0; i < n; i++){
		 String str = cin.next();
		 str = str.replaceAll("cRazY", "CrAZy");
		 str = str.replaceAll("CraZy", "cRAzY");
		 System.out.println(str);
	 }
	}

}


import java.util.*;

public class Main {
  static void change(char op){
	   if(op >= 'a' && op <= 'z')
		   System.out.print((char)(op-'a' + 'A'));
	   else if(op >= 'A' && op <= 'Z')
		   System.out.print((char)(op-'A' + 'a'));
   }
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		
		for(int t = 0; t < n; t ++){
			String s = cin.next();
		  if(s.length() < 5){
			    System.out.println(s);
			  continue;
		  }
			
			char str1[] = s.toCharArray();
			for(int i = 0; i < s.length()  - 4; i++){
				if(str1[i]=='C' && str1[i+1] == 'r' && str1[i+2] == 'a' && str1[i+3] == 'Z' && str1[i+4] == 'y' ){
					str1[i] = 'c';
					str1[i+1] = 'R';
					str1[i+2] = 'A';
					str1[i+3] = 'z';
					str1[i+4] = 'Y';
				
					
				}
			 if(str1[i]=='c' && str1[i+1] == 'R' && str1[i+2] == 'a' && str1[i+3] == 'z' && str1[i+4] == 'Y' ){
					str1[i] = 'C';
					str1[i+1] = 'r';
					str1[i+2] = 'A';
					str1[i+3] = 'Z';
					str1[i+4] = 'y';
					
				}
				
				
			}
			for(int i = 0; i < s.length(); i++)
				System.out.print(str1[i]);
		  System.out.println();
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值