m和n是一对Couple数字在十进制中我们规定:每一位由m和n两个数字组成的正整数Y都叫冤家数

m和n是一对Couple数字(1<=m<n<=9),在十进制中,我们规定:每一位由m和n两个数字组成的正整数Y都叫冤家数,当m=3,n=8时,冤家数从小到大为:3,8,33,38,83,88.......

样例输入:

2

3 8 5

3 7 100

83

733737

package com.zhicheng.itcast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class YuanJiaShu {

    //转化为规定长度的二进制数
    public static String binary2decimal(int decNum , int digit) {
        String binStr = "";
        for(int i= digit-1;i>=0;i--) {
            binStr +=(decNum>>i)&1;
        }
        return binStr;
    }

    public static void Fun(int m, int n, int K1) {
        int count = 0;
        int i = 0;
        int K = K1;
        while (K1 > 1) {
            K1 = K1 / 2;
            count++;
        }
        
        System.out.println(count);
        int temp = (int) (K - (int)Math.pow(2, count));
        String string = binary2decimal(temp+1, count);
        StringBuffer sb = new StringBuffer();
        for (i = 0; i < string.length(); i++) {
            if (string.charAt(i) == '0') {
                sb.append(Math.min(m, n));
            } else {
                sb.append(Math.max(m, n));
            }
        }
        System.out.println(sb.toString());
    }


    public static void main(String[] args) throws IOException {
        int m = 0;
        int n = 0;
        int K1 = 0;
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int K = Integer.parseInt(bf.readLine());

        String[] arr = new String[K];
        int i = 0;

        for (i = 0; i < K; i++) {
            String s1 = bf.readLine();
            arr[i] = s1;
        }

        for (i = 0; i < arr.length; i++) {
            String arr1[] = arr[i].split(" ");
            for (int j = 0; j < arr1.length; j++) {
                m = Integer.parseInt(arr1[0]);
                n = Integer.parseInt(arr1[1]);
                K1 = Integer.parseInt(arr1[2]);
            }
            Fun(m, n, K1);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值