NC16644字符串的展开
字符串的展开
https://ac.nowcoder.com/acm/problem/16644?&headNav=acm
import java.util.Scanner;
public class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int p1 = sc.nextInt();
int p2 = sc.nextInt();
int p3 = sc.nextInt();
String kong = sc.nextLine();
String str1 = sc.nextLine();
for(int i = 1;i<str1.length()-1;i++){
char ch1 = str1.charAt(i);
if(ch1=='-'){
String str2 = fun(p1, p2, p3, str1.charAt(i-1), str1.charAt(i+1));
str1 = str1.substring(0, i)+str2+str1.substring( i+1,str1.length());
}
}
System.out.println(str1);
}
public static String fun(int p1,int p2,int p3,char ch1,char ch2){
if((int)ch1>=97&&(int)ch1<=122&&(int)ch2>=97&&(int)ch2<=122){
if((int)ch2<=(int)ch1){
return "-";
}else{
String str1 = "";
if(p1==3){
for(int i=(int)ch1+1;i<(int)ch2;i++){
for(int j = 0;j<p2;j++){
str1+="*";
}
}
return str1;
}
if(p3==1){
for(int i=(int)ch1+1;i<(int)ch2;i++){
for(int j = 0;j<p2;j++){
str1+=(char)i;
}
}
}else{
for(int i=(int)ch2-1;i>=(int)ch1+1;i--){
for(int j = 0;j<p2;j++){
str1+=(char)i;
}
}
}
if(p1==1) return str1;
else return str1.toUpperCase();
``` js
}
}else if((int)ch1>=48&&(int)ch1<=57&&(int)ch2>=48&&(int)ch2<=57){
if((int)ch2<=(int)ch1){
return "-";
}else{
String str1 = "";
if(p1==3){
for(int i=(int)ch1+1;i<(int)ch2;i++){
for(int j = 0;j<p2;j++){
str1+="*";
}
}
return str1;
}
if(p3==1){
for(int i=(int)ch1+1;i<(int)ch2;i++){
for(int j = 0;j<p2;j++){
str1+=(char)i;
}
}
}else{
for(int i=(int)ch2-1;i>=(int)ch1+1;i--){
for(int j = 0;j<p2;j++){
str1+=(char)i;
}
}
}
return str1;
}
}
return "-";
} }