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 ();
}
}
}