您的位置:首页 > 编程语言 > Java开发

360java笔试编程第二题20160328

2016-03-28 23:50 411 查看
题目内容如下:





按照个人理解,写出了ac率为20%的程序如下:

import java.util.Scanner;

public class replaceASCII {
public static void main(String[] args){
int index=0;
String replaceChar;
StringBuilder strbu;
Scanner s = new Scanner(System.in);
System.out.println("请输入数据:");
int n = s.nextInt();
int m = s.nextInt();
s.nextLine();
String str=s.nextLine();
if(str.length()!=n){
System.out.println("输入不合法");
return;
}
for(int line=0;line<m;line++){
index = s.nextInt();
replaceChar = s.next();
if(replaceChar.length()!=1){
System.out.println("输入不合法");
return;
}
strbu = new StringBuilder(str);
strbu.replace(index-1,index,replaceChar);
str = strbu.toString();
System.out.println(replaceFun(str));
}

}

public static int replaceFun(String string){
int replaceTime = 0;
while(string.contains("..")){
string = string.replaceFirst("\\.\\.",".");
replaceTime++;
}
return replaceTime;
}
}


也不知道是哪里没有考虑到,求各位指教~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: