程序设计天梯赛——练习集(Java版)

程序设计天梯赛——练习集(Java版)

(五分题)

Hello World

输出hello world

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

计算摄氏温度

给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:C=5×(F32)/9。题目保证输入与输出均在整型范围内。
import java.util.Scanner;

/**
 * @author 辉欲静,而风止。
 * Hello World
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        
        int f= sc.nextInt();
        int c = 5*(f-32)/9;
        System.out.printf("Celsius = %d",c);
    }
}

计算指数

对任意给定的不超过 10 的正整数 n,要求你输出 2 的n次方
#include <stdio.h>
#include <math.h>
int main()
{
    int n,h;
    scanf("%d",&n);
    h=pow(2,n);
    printf("2^%d = %d\n",n,h);
    return 0;
}

简单题

public class Main{
    public static void main(String[] a){
        System.out.println("This is a simple problem.");
    }
}

重要的话说三遍

#include <stdio.h>
int main(){
    for(int i=0;i<3;i++)
        
        printf("I\'m gonna WIN!\n");
    
    return 0;
}

后天

如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几

输入格式

输入第一行给出一个正整数D1D7),代表星期里的某一天。

输出格式

在一行中输出D天的后天是星期几。
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int res = (D + 2) % 7;
        if (res == 0) {
            System.out.println("7");
        } else {
            System.out.println(res);
        }
    }
}

输出 I Love GPLT

public class Main {
    public static void main(String[] args) {
        System.out.println("I\n" +
                " \n" +
                "L\n" +
                "o\n" +
                "v\n" +
                "e\n" +
                " \n" +
                "G\n" +
                "P\n" +
                "L\n" +
                "T");
    }
}

是不是太胖了

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。已知市斤的数值是公斤数值的两倍。现给定某人身高,请你计算其标准体重应该是多少?(顺便也悄悄给自己算一下吧……)

输入格式

输入第一行给出一个正整数H100 < H300),为某人身高。

输出格式

在一行中输出对应的标准体重,单位为市斤,保留小数点后1位。
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        double H;
        Scanner sc = new Scanner(System.in);
        H = sc.nextDouble();
        double a = ((H-100)*0.9)*2;
        System.out.println(a);
    }
}

A乘以B

输入格式:

输入在第一行给出两个整数 AB(−100≤A,B≤100),数字间以空格分隔。

输出格式:

在一行中输出 A 乘以 B 的值。

输入样例:

-8 13
结尾无空行

输出样例:

-104

结尾无空行
import java.util.Scanner;
public class Main{
    public static void main(String[] a){
        int A,B;
        Scanner sc = new Scanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        System.out.println(A*B);
    }
}

新世界

public class Main{
    public static void main(String[] a){
        System.out.println("Hello World"+"\n"+
								"Hello New World");
    }
}

日期格式化

世界上不同国家有不同的写日期的习惯。比如美国人习惯写成“月-日-年”,而中国人习惯写成“年-月-日”。下面请你写个程序,自动把读入的美国格式的日期改写成中国习惯的日期。

输入格式:

输入在一行中按照“mm-dd-yyyy”的格式给出月、日、年。题目保证给出的日期是1900年元旦至今合法的日期。

输出格式:

在一行中按照“yyyy-mm-dd”的格式给出年、月、日。

输入样例:

03-15-2017
结尾无空行

输出样例:

2017-03-15
结尾无空行
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("-");
        System.out.print(s[2]+"-");
        System.out.print(s[0]+"-");
        System.out.print(s[1]);

    }
}

打折

import java.util.Scanner;

/**
 * @author 辉欲静,而风止。
 * 打折
 */
public class Solution51 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        int discount = sc.nextInt();
        double endPrice = price*(0.1*discount);

        System.out.printf("%.2f",endPrice);
    }
}

2018我们要赢

public class Solution52 {
    public static void main(String[] args) {
        System.out.println("2018\n" +
                "wo3 men2 yao4 ying2 !");
    }
}

PTA使我精神焕发

public class Solution57 {
    public static void main(String[] args) {
        System.out.println("PTA shi3 wo3 jing1 shen2 huan4 fa1 !");
    }
}

心理阴影面积

import java.util.Scanner;

public class Solution60 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        int y = sc.nextInt();
        int res = 5000 - ((100-x)*y+x*y/2+(100-x)*(100-y)/2);
        System.out.println(res);
    }
}

两小时学完C语言

import java.util.Scanner;

/**
 * @author 辉欲静,而风止。
 * 两小时学完C语言
 */
public class Solution74 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int M = sc.nextInt();
        int res = N-(M*K);
        System.out.println(res);
    }
}

版权声明:本文为m0_53679492原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。