string expansion

Problem Description

Tom sometimes used the extension character '-' to simply represent some consecutive characters for the convenience of recording. For example , abcdefg can be abbreviated as ag, that is, an extension '-' is added between the starting character and the ending character to represent the string. But for the convenience of processing, Tom must expand these simple notation into the original string. Obviously it would be a hassle to do it manually, and Tom knew that a computer could help him with this task, but he couldn't program, which really got him mad. He knew that today was the day of the third ACM school competition of Shandong University of Technology, and programming enthusiasts from all over the school would come to participate in the competition. He was very excited, because the problem that had puzzled him for a long time was finally solved. Given a string containing the extension '-' , your task is to restore it to the original string. The requirement is to only process character expansion in the range of [az] , [AZ] , [0-9] , that is, only when the characters before and after the expansion are lowercase letters, uppercase letters or numbers at the same time and the characters before the expansion are not larger than the characters after The characters are expanded only in other cases, and they are output as they are. For example: aR , De , 0-b , 4-B , etc. strings are not expanded.

Input

The first line is a positive integer T, indicating that there are T groups of test data (T < 100). The following T lines, each line contains a string to be expanded with a length not greater than 1000.

Output

Each set of test data outputs a line of expanded strings.

Sample Input

3
ADEa-g-m02
acm-0-5-a-ac-cm-mA-AC-CM-M
Welcometothe3rdACM/ICPCCampusProgrammingContestofSDUT-1-3-A-z-a-Z

Sample Output

ADEabcdefghijklm02
acm-012345-aaccmm-AACCMM
Welcometothe3rdACM/ICPCCampusProgrammingContestofSDUT-123-A-z-a-Z

code:

import java.util. *;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner reader = new Scanner(System.in);
		
		int t;
		t = reader.nextInt();
		while(t-->0)
		{
			String str = reader.next();
			String result = "";
			for(int i = 0;i<str.length();i++)
			{
				if(str.charAt(i) == '-'&&i!=0&&i!=str.length()-1)
				{
					if(str.charAt(i-1)<=str.charAt(i+1)&&((str.charAt(i-1)>='0'&&str.charAt(i+1)<='9')||(str.charAt(i-1)>='a'&&str.charAt(i+1)<='z')||(str.charAt(i-1)>='A'&&str.charAt(i+1)<='Z')))
					{
						for(int j = str.charAt(i-1)+1;j<str.charAt(i+1);j++)
						{
							result+=(char)j;
						}
					}
					else result+='-';
				}
				else result+=str.charAt(i);
			}
			System.out.println(result);
		}
	}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325544069&siteId=291194637