HDU-1020-Encoding(Java && 弱水三千)

Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 31603    Accepted Submission(s): 14020

Problem Description

Given a string containing only ‘A‘ - ‘Z‘, we could encode it using the following method:

1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.

2. If the length of the sub-string is 1, ‘1‘ should be ignored.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only ‘A‘ - ‘Z‘ and the length is less than 10000.

Output

For each test case, output the encoded string in a line.

Sample Input

2
ABC
ABBCCC

Sample Output

ABC
A2B3C

Author

ZHANG Zheng

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1019 1021 1062 1032 1018

很简单的水题,我不会告诉你我是无聊才来切水题的!

题目的主要意思就是:让你求一个字符串里面连续的不同字符的个数,注意是连续的字符!

所以AABCCA的结果是2AB2CA而不是3AB2C!就只有这一个坑点了,其他没有了......

另外注意如果字符是1前面不输出1......

import java.io.*;
import java.util.*;

public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int a[] = new int[10005];
		int n = input.nextInt();
		input.nextLine();
		for (int i = 0; i < n; i++)
		{
			int count = 1;
			String str = input.nextLine();
			char c[] = str.toCharArray();
			for (int j = 1; j < c.length; j++)
			{
				if (c[j] == c[j - 1])
				{
					++count;
				}
				else
				{
					if (count == 1)
					{
						System.out.print(c[j - 1]);
					}
					else
					{
						System.out.print(count + "" + c[j - 1]);
						count = 1;
					}
				}
				if (j == c.length - 1)
				{
					if (count == 1)
					{
						System.out.print(c[j]);
					}
					else
					{
						System.out.print(count + "" + c[j]);
						count = 1;
					}
				}
			}
			System.out.println();
		}
	}

}
时间: 2024-12-21 09:48:01

HDU-1020-Encoding(Java && 弱水三千)的相关文章

hdu 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40214    Accepted Submission(s): 17846 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

HDU 1020 Encoding 模拟

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39047    Accepted Submission(s): 17279 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

杭电 HDU 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29834    Accepted Submission(s): 13212 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the follow

HDU 1020 Encoding【连续的计数器重置】

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51785    Accepted Submission(s): 23041 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

HDU 1020 Encoding 字符串

基本的字符串处理转换. 喷一喷HDU这个超级垃圾的判断系统:如果把数字存入字符串数组中输出就会错误. 如:A2B3C,如果其中的2和3保存如字符串数组中,然后输出那么就判断为WA,必须是即时输出数字2和3才算正确. 这样判我WA,哎, HDU做好点你们的判断系统吧. #include <string> #include <iostream> using namespace std; int main() { int T; string s; scanf("%d"

HDU 1020 Encoding 字符统计

Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.2

HDU 1020:Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25691    Accepted Submission(s): 11289 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the follow

HDU - 1042 - N! - JAVA

http://acm.hdu.edu.cn/showproblem.php?pid=1042 大数嘛,直接用JAVA. 为什么要开64路?好像我觉得会快一点--其实并没有快-- import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while

hdu 2023 简单java 水过~~~

Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. Input 输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数.然后是n行数据,每行包括m个整数(即:考试分数). Output 对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数:第二行包含m个数据,表示m门课的平均成绩,结果保留