Antique Typography + Big Ben + Cosmic Invincible Adder + Valentine's Day

L1-1 Antique typography

中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
输入格式:

输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:

按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。
输入样例:

4
This is a test case

输出样例:

asa T
st ih
e tsi
 ce s

answer:

import java.util.Scanner;

/** 
 * @author 作者 : Cactus
 * @version 创建时间:2018-3-25 下午01:35:06 
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str_drop = sc.nextLine();
        String str = sc.nextLine();
        sc.close();
        int length = str.length();
        char[][] arr = new char[(length / n) + 1][n];
        int i = 0;
        for(int j = 0; j <= (length / n); j++){
            for(int k = 0; k < n; k++){
                if(i >= length){
                    arr[j][k] = ' ';
                    i++;
                }else{
                    arr[j][k] = str.charAt(i);
                    i++;
                }
            }
        }

            for(int k = 0; k < n; k++){
                for(int j = 0; j <= (length / n); j++){
                    System.out.print(arr[(length / n) - j][k]);
                }
                System.out.println();
            }
    }

}

L1-2 Big Ben

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。
输入格式:

输入第一行按照hh:mm的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。
输出格式:

根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang。如果不是敲钟期,则输出:

Only hh:mm.  Too early to Dang.

其中hh:mm是输入的时间。
输入样例1:

19:05

输出样例1:

DangDangDangDangDangDangDangDang

输入样例2:

07:05

输出样例2:

Only 07:05.  Too early to Dang.

answer:

import java.util.Scanner;

/** 
 * @author 作者 : Cactus
 * @version 创建时间:2018-3-25 下午02:27:57 
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] str = sc.next().split(":");
        sc.close();
        int hour = Integer.valueOf(str[0]);
        String hourStr = str[0];
        int minite = Integer.valueOf(str[1]);
        String miniteStr = str[1];
        if((hour >= 0 && hour < 12) || (hour == 12 && minite == 0)){
            System.out.println("Only "+hourStr+":"+miniteStr+".  Too early to Dang.");
        }else{
            if(minite == 0){
                for(int i = 0; i < hour % 12; i++){
                    System.out.print("Dang");
                }
            }else{
                for(int i = 0; i < (hour % 12) + 1; i++){
                    System.out.print("Dang");
                }
            }
        }

    }
}

L1-3 Universe Invincible Adder

地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT 星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10 进制数,等等。每一位的进制 d 或者是 0(表示十进制)、或者是 [29] 区间内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT 星人通常只需要记住前 20 位就够用了,以后各位默认为 10 进制。

在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何计算“6203 + 415”呢?我们得首先计算最低位:3 + 5 = 8;因为最低位是 7 进制的,所以我们得到 11 个进位。第 2 位是:0 + 1 + 1(进位)= 2;因为此位是 2 进制的,所以我们得到 01 个进位。第 3 位是:2 + 4 + 1(进位)= 7;因为此位是 5 进制的,所以我们得到 21 个进位。第 4 位是:6 + 1(进位)= 7;因为此位是 10 进制的,所以我们就得到 7。最后我们得到:6203 + 415 = 7201
输入格式:

输入首先在第一行给出一个 N 位的进制表(0 < N20),以回车结束。 随后两行,每行给出一个不超过 N 位的非负的 PAT 数。
输出格式:

在一行中输出两个 PAT 数之和。
输入样例:

30527
06203
415

输出样例:

7201

answer:

import java.util.Scanner;

/** 
 * @author 作者 : Cactus
 * @version 创建时间:2018-3-25 下午02:52:07 
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String tables = sc.nextLine();
        String num1s = sc.nextLine();
        String num2s = sc.nextLine();
        sc.close();
        char[] table = tables.toCharArray();
        char[] num1 = num1s.toCharArray();
        char[] num2 = num2s.toCharArray();
        int tableLength = table.length, num1Length = num1.length, num2Length = num2.length;
        int resultLenth = num1Length > num2Length ? num1Length : num2Length;
        int[] arrTable = new int[tableLength];
        int[] arrNum1 = new int[resultLenth];
        int[] arrNum2 = new int[resultLenth];
        for(int i = 0; i < tableLength; i++){
            if('0' == table[i]){
                arrTable[i] = 10;
            }else{
                arrTable[i] = table[i] - '0';
            }
        }
        for(int i = 0; i < resultLenth; i++){
            if(i >= num1Length){
                arrNum1[resultLenth - 1 - i] =0;
            }else{
                arrNum1[resultLenth - 1 - i] = num1[num1Length - 1 - i] - '0';
            }

        }
        for(int i = 0; i < resultLenth; i++){
            if(i >= num2Length){
                arrNum2[resultLenth - 1 - i] =0;
            }else{
                arrNum2[resultLenth - 1 - i] = num2[num2Length - 1 - i] - '0';
            }   
        }

        int[] arrResult = new int[resultLenth];
        int num = 0;
        for(int i = 0; i < resultLenth; i++){
            arrResult[resultLenth - 1 - i] = (arrNum1[resultLenth - 1 - i] + arrNum2[resultLenth - 1 - i] + num) % arrTable[resultLenth - 1 - i];
            num = (arrNum1[resultLenth - 1 - i] + arrNum2[resultLenth - 1 - i] + num) / arrTable[resultLenth - 1 - i];
        }
        int flag = 0;
        for(int i = 0; i < resultLenth; i++){
            if(flag == 0){
                if(arrResult[i] != 0){
                    System.out.print(arrResult[i]);
                    flag = 1;
                    continue;
                }else{
                    continue;
                }
            }else{
                System.out.print(arrResult[i]);
            }
        }
    }
}

L1-4 Valentine's Day



以上是朋友圈中一奇葩贴:“214情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋。
输入格式:

输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空单词,以回车结束。一个英文句点.标志输入的结束,这个符号不算在点赞名单里。
输出格式:

根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner...”;若只有A没有B,则输出“A is the only one for you...”;若连A都没有,则输出“Momo... No one is for you ...”。
输入样例1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

输出样例1:

Magi and Potaty are inviting you to dinner...

输入样例2:

LaoLao
FatMouse
whoever
.

输出样例2:

FatMouse is the only one for you...

输入样例3:

LaoLao
.

输出样例3:

Momo... No one is for you ...

answer:

import java.util.ArrayList;
import java.util.Scanner;

/** 
 * @author 作者 : Cactus
 * @version 创建时间:2018-3-25 下午04:06:53 
 */
public class Main {
    private static String[] names = new String[10000];
    public static void main(String[] args){
        int n = 0;
        String name, flag = ".";
        Scanner sc = new Scanner(System.in);
        for(int i = 0; i < 10000; i++){
            name = sc.next();
            if(!flag.equals(name)){
                names[i] = name;
                n++;
            }else{
                break;
            }
        }
        if(n < 2){
            System.out.println("Momo... No one is for you ...");
        }else if(n < 14){
            System.out.println(names[1]+" is the only one for you...");
        }else{
            System.out.println(names[1]+" and "+names[13]+" are inviting you to dinner...");
        }
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518645&siteId=291194637
Recommended