HDOJ-ACM1020(JAVA)

题意:给字母计数,如果是字母后面没有相同的,原样输出,如果有则输出这个字母的个数和字母本身。

import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] arg){
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n =scan.nextInt();
        while(n--!=0){
            String s = scan.next();
            char[] cs = s.toCharArray();
            int len = cs.length;
            int count = 1;
            int last = len -1;
            String result = "";
            for(int i = 0 ; i != len ; i ++){
                if(i!=last&&cs[i] == cs[i+1]){
                    count++;
                    continue;
                }
                if(count == 1){
                    result = result +  cs[i];
                    continue;
                }
                result = result + count + cs[i];
                count=1;
            }
            System.out.println(result);
        }
        scan.close();

    }

}
时间: 2025-01-05 00:36:04

HDOJ-ACM1020(JAVA)的相关文章

HDOJ 1000 java

第一次做hdoj 试了好几次才通过 发现主类的名字必须是Main import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); while(scanner.hasNext()) { int A=scanner.nextInt(); int B=scanner.nextInt(); System.out.p

ACM--大数阶乘--HDOJ 1042--N!--Java

HDOJ题目地址:传送门 N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 74952    Accepted Submission(s): 21832 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Inp

HDOJ 1001 java

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); int sum,n; while(scanner.hasNext()) { n=scanner.nextInt(); sum=0; for(int i=1;i<=n;i++) { sum+=i; } System.out.println(sum

HDOJ 1002 java

import java.math.BigInteger; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); int n=scanner.nextInt(); for(int i=1;i<=n;i++) { BigInteger a=sca

hdoj 1007 java MLE通不过

参考网上的一个算法,但是一直都是MLE,实在是想不出来什么办法了. 参考博客:编程之美寻找最近点对 import java.util.Arrays; import java.util.Scanner; public class Main { public static int N=100000; public static int[] list=new int[N]; public static Point[] ptns=new Point[N]; public static float MAX

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

hdoj 1316 How Many Fibs? 【Java大数】+【打表】

现将前1000个的斐波那契数打表,然后再找就好了. 代码: import java.util.Scanner; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); BigInteger[] s = new BigInteger[1005]; s[1] = new BigInteger("1"); s[2]

HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题. 亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串. Input 本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二

hdoj 1753 大明A+B 高精度/java

大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9273    Accepted Submission(s): 3318 Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”.这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加

hdoj 1002 A + B Problem II 高精度 java

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 241933    Accepted Submission(s): 46646 Problem Description I have a very simple problem for you. Given two integers A and B, you