Palindrome decoding

topic

Here Insert Picture Description
Here Insert Picture Description

Thinking

This problem mainly on the mastery of the string / StringBuffer of
Stringbuffer by subString (start, end)
taken out of the corresponding character
reverse () may be reversed
append (StringBuffer) and added to the back
String dividing method split ( "")

import java.util.Scanner;

/**
 * 
 */

/***
 * @author 18071
 * @Date 2019年3月14日
 * 功能:
 ***/
public class test {
 public static void main(String args[]) {
	 solution s=new solution();
	 s.so();
 }
}

class solution{

	public void so () {
		Scanner input =new Scanner(System.in);
		
		StringBuffer a = new StringBuffer(input.next());
		System.out.println(a);
		
		int num=input.nextInt();
		System.out.println("  num:" +num);
		  input.nextLine();
		 for(int i=0;i<num;i++) {
		    String[] rua = input.nextLine().split(" ");
		    int p= Integer.parseInt(rua[0]);
		    System.out.println("p "+p);
		    int l= Integer.parseInt(rua[1]);
		    System.out.println("l "+l);
		    StringBuffer sub =new StringBuffer(a.substring(p,p+l));
		    sub.reverse();
		    System.out.println(sub);
		    a.append(sub);
		    System.out.println("a is "+a);
		  }
	}
	
}

Run shot

Here Insert Picture Description

* Revolution is not successful, comrades need to strive *

Published 68 original articles · won praise 3 · Views 5239

Guess you like

Origin blog.csdn.net/Hqxcsdn/article/details/88567531