0
点赞
收藏
分享

微信扫一扫

51单片机使用uart串口和助手简单调试

黎轩的闲暇时光 04-06 12:00 阅读 1

题目描述:

从X星截获一份电码,是一些数字,如下:
13
1113
3113
132113
1113122113
....

YY博士经彻夜研究,发现了规律:
第一行的数字随便是什么,以后每一行都是对上一行“读出来”
比如第2行,是对第1行的描述,意思是:1个1,1个3,所以是:1113
第3行,意思是:3个1,1个3,所以是:3113

请你编写一个程序,可以从初始数字开始,连续进行这样的变换。

代码:

package lanqiao;

import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = sc.nextInt();
        for(int i = 0;i < n;i ++)
        {
            char[] temp = s.toCharArray();
            int tempcount = 1;
            s = "";
            for(int j = 0;j <temp.length - 1;j ++)
            {
                if(temp[j] == temp[j + 1])
                {
                    tempcount += 1;
                }
                else{
                    s += tempcount+""+temp[j];
                    tempcount = 1;
                }
            }
            s += tempcount+""+temp[temp.length - 1];

            if(i == n - 1)
            {
                System.out.println(s);
                break;
            }
        }
    }
}
举报

相关推荐

0 条评论