码迷,mamicode.com
首页 > 其他好文 > 详细

pat甲级 1027 Colors in Mars

时间:2021-04-08 13:28:06      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:array   sim   you   ext   similar   ati   output   ddl   can   

题目:People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue.

The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.

题目大致意思就是,会输入三个数字,用空格隔开,将数字转化成为十三进制(radix)的数,前面加上“#”,然后中间去掉空格

import java.util.Scanner;
public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int array[] = new int[3];

        for(int i=0;i<array.length;i++){
            array[i] = scanner.nextInt();//将十进制转化成为13进制
        }
        System.out.print("#");
        for(int i=0;i<array.length;i++){
            if(array[i]/13<10){
                System.out.print(array[i]/13);

            }
            else if(array[i]/13==10){
                System.out.print("A");
            }
            else if(array[i]/13==11){
                System.out.print("B");
            }
            else if(array[i]/13==12){
                System.out.print("C");
            }
            if(array[i]%13<10){
                System.out.print(array[i]%13);

            }
            else if(array[i]%13==10){
                System.out.print("A");
            }
            else if(array[i]%13==11){
                System.out.print("B");
            }
            else if(array[i]%13==12){
                System.out.print("C");
            }
        }




    }
}

 

pat甲级 1027 Colors in Mars

标签:array   sim   you   ext   similar   ati   output   ddl   can   

原文地址:https://www.cnblogs.com/tonychen88/p/14628246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!