Huawei machine Test--string loop conversion

Source: Internet
Author: User
Package com.abuge;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import java.io.UnsupportedEncodingException;

Import Java.util.HashMap;

Import Org.junit.Test; /** * * 1 String conversion problem Description: Converts the input strings (strings containing only lowercase letters ' a ' to ' Z ') according to the following rules, cyclic conversion after the output: A->b,b->c,..., y->z,z->a; If the string entered in successive occurrences of two letters, The last letter needs to be converted 2 consecutive times.
	For example: AA converts to Bc,zz to AB, and when the same number of consecutive letters exceeds two, the third occurrence of the letter is counted for the first time. Required implementation function: void convert (char *input,char* output) "Input" char *input, input string "output" char *output, output string "Return" no sample input: ch ar*input= "ABCD" Output: char*output= "BCDE" Input: char*input= "ABBBCD" Output: char*output= "BCDCDE" * @author Abuge */public C
		Lass Interviewdemo {public static void main (string[] args) {String input = ' ABBBCD ';
		String output= null;
	Convert (input, output);
		public static void Convert (string input, string output) {int count = 0;
		
		Read one line of string, convert string to string array char[] Strarray = Input.tochararray ();
		char tmp = 0; Iterate over a string for (int i = 0; i < Strarray.lenGth
				
				i++) {if (Strarray[i]!= tmp) {tmp = Strarray[i];
				
				Strarray[i] = (char) ((Strarray[i] + 1)% + ' a ');
			Count = 1;
					}else {if (count = = 1) {Strarray[i] = (char) ((strarray[i) + 2)% + ' a ');
				Count = 0;
					}else {Strarray[i] = (char) ((strarray[i) + 1)% + ' a ');
				Count = 1;
		Output = new String (strarray);
	SYSTEM.OUT.PRINTLN (output); }
----------------------------------------------Keyboard Input-----------------------------------------------------------------------
		--------------------------@Test public void Testconvert () {BufferedReader bufr = null;
		BUFR = new BufferedReader (new InputStreamReader (system.in));
		String strinput = null;
		String stroutput = null;
		int count = 0; The try {while (strinput = Bufr.readline ())!= null) {//reads to a line of strings, converts a string to an array of strings char[] Strarray = Strinput.toc
				Hararray ();
				char tmp = 0; Iterate the string for (int i = 0; i < strarray.length i++) {if (strarray[i)!= tmp) {tmp = Strarray
						
						[i];
						
						Strarray[i] = (char) ((Strarray[i] + 1)% + ' a ');
					Count = 1;
							}else {if (count = = 1) {Strarray[i] = (char) ((strarray[i) + 2)% + ' a ');
						Count = 0;
							}else {Strarray[i] = (char) ((strarray[i) + 1)% + ' a ');
						Count = 1; }} stroutput = new String (strarRay);
			System.out.println (Stroutput);
		} catch (IOException e) {e.printstacktrace ();
 }
	}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.