java练习——int indexOf(String ,int) 2022-05-25 22:43 137阅读 0赞 ### 救基友记2 ### Time Limit: 1000 ms Memory Limit: 65536 KiB [Submit][] [Statistic][] #### 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 行,表示转换后的字符串 #### Sample Input #### 2 abjbjhcRazYdcRazYCraZy bbbnnnbbn #### Sample Output #### abjbjhCrAZydCrAZycRAzY bbbnnnbbn #### #### String 类真是强大,用一个indexOf(String ,int),直接相当于模式匹配,简单操作。 import java.util.*; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); while(t-->0) { String s = cin.next(); int i = 0,j; for(i = 0;i<s.length();i++) { if(s.indexOf("CraZy", i)==-1&&s.indexOf("cRazY", i)==-1) {//如果返回-1,说明再这个字符串中没有与之匹配的,则全部输出 for(j =i;j<s.length();j++ ) { System.out.print(s.charAt(j)); } break; } else if(s.indexOf("CraZy", i)==i) {//返回当前i,说明从当前开始匹配,则直接输出变换后的字符串输出 System.out.print("cRAzY"); i = i+4; } else if(s.indexOf("cRazY", i)==i) { System.out.print("CrAZy"); i = i+4; } else System.out.print(s.charAt(i)); } System.out.println(); } } } [Submit]: http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestsubmit/cid/2435/pid/2192.html [Statistic]: http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/conteststatus/cid/2435/pid/2192.html
相关 java int在那个包_int intValue() int intValue() 描述 (Description) java.lang.Double.intValue()方法将此Double的值作为int返回(通过强制转换为 清疚/ 2022年11月03日 11:13/ 0 赞/ 15 阅读
相关 const *int、int const *、int *const的区别 include<iostream> using namespace std; static int test = 1; const i - 日理万妓/ 2022年10月16日 04:56/ 0 赞/ 95 阅读
相关 Golang的Int8 Int16 Int32 Int64区别 位(bit):二进制数中的一个数位,可以是0或者1,是计算机中数据的最小单位 字节(Byte B):计算机中数据的基本单位,每8位组成一个字节 字(Word):两个字节称为 ╰+哭是因爲堅強的太久メ/ 2022年09月02日 12:59/ 0 赞/ 98 阅读
相关 const int a; int const a; const int *a; int * const a; const int * const a; 对指针来说,可以指定指针本身为const,也可以指定指针所指的数据为const,或二者同时指定为const。 1)const int a; int const a; 这 野性酷女/ 2022年08月08日 15:56/ 0 赞/ 120 阅读
相关 [转载]int,int32_t,int64_t 原文地址:[int,int32\_t,int64\_t][int_int32_t_int64_t] 作者: [走向希望][Link 1] 这些事跨平台编程导致的;一、数据类型 淡淡的烟草味﹌/ 2022年06月13日 02:21/ 0 赞/ 109 阅读
相关 int (*p)(int x)和int* p(int x)的区别 int (\p)(int x)是函数指针 可以直接使用,它的返回值是int型 int\ p(int x);是一个返回值为int型指针的函数的声明 不能直接用, 桃扇骨/ 2022年06月06日 12:39/ 0 赞/ 141 阅读
相关 java练习——int indexOf(String ,int) 救基友记2 Time Limit: 1000 ms Memory Limit: 65536 KiB [Submit][] [Statistic][] Problem 刺骨的言语ヽ痛彻心扉/ 2022年05月25日 22:43/ 0 赞/ 138 阅读
相关 C# 中int short Int16 Int32 Int64详解 Java中没有Int32,Int64,,只有int,short,long Java中int就代表Int32 ,short就代表Int16,long就代表Int64 首先, 男娘i/ 2022年05月09日 14:06/ 0 赞/ 267 阅读
相关 golang string 转 int, int64, int32 str := “123” // string 转 int i, err := strconv.Atoi(str) if err == nil \{ fmt. 比眉伴天荒/ 2022年03月09日 00:22/ 0 赞/ 587 阅读
相关 .net Int16 、(int Int32)、 Int64 的区别 [2019独角兽企业重金招聘Python工程师标准>>> ][2019_Python_] ![hot3.png][] .net Int16 、(int Int32)、 In 客官°小女子只卖身不卖艺/ 2022年01月14日 04:25/ 0 赞/ 158 阅读
还没有评论,来说两句吧...