天梯赛每日打卡03(13-25题解)

Posted Huterox

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了天梯赛每日打卡03(13-25题解)相关的知识,希望对你有一定的参考价值。

文章目录

前言

打卡第三天,今天水课比较多,多刷几个题目,看看下个礼拜能不能刷到level 2。目前来看除了那个连续因子的题目,我觉得很有意思,其他的还没遇到更好玩的.

今天做的题目还是简单的,但是那些格式,和输入数据的细节真的是,不跑不知道,一跑吓一跳。
还是按照难易排序。

稍晚一点还有一篇关于从0开始制作自己的分类“框架”。只要是模仿yolo的工程的基本结构,玩玩儿~

L1-014 简单题 (5 分)


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


L1-021 重要的话说三遍 (5 分)


public class Main 
    //先水几题
    public static void main(String[] args) 
        for (int i = 0; i < 3; i++) 
            System.out.println("I'm gonna WIN!");
        
    

        

L1-024 后天 (5 分)

import java.util.Scanner;

public class Main 

	public static void main(String[] args) 
		int a[]= 1,2,3,4,5,6,7;
		int b[]= 3,4,5,6,7,1,2;
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
	    if(D<=7)
            System.out.println(b[D-1]);
        
		
	



L1-022 奇偶分家 (10 分)


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main 
    public static void main(String[] args) 
        int count_j = 0;
        int count_o = 0;
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int N = scanner.nextInt();
        for (int i = 0; i < N; i++) 
            if(scanner.nextInt()%2==0)
                count_o++;
            else 
                count_j++;
            
        
        System.out.println(count_j+" "+count_o);
    


L1-013 计算阶乘和 (10 分)

暴力直接过

import java.util.Scanner;
 
public class Main 
	public static void main(String args[]) 
		Scanner std=new Scanner(System.in);
		int N=std.nextInt();
		int Sum=0,num=1;
		for(int i=1;i<=N;i++) 
                //计算第i个数的阶乘
			num=num*i;
                //求阶乘和
			Sum+=num;
		
		System.out.println(Sum);
	
 

L1-018 大笨钟 (10 分)

这个题目注意细节,注意输入。

import java.util.Scanner;

public class Main 
    public static void main(String[] args) 

        Scanner scanner = new Scanner(System.in);
        String time = scanner.next();
        String[] times = time.split(":");
        int H = Integer.parseInt(times[0]);
        int M = Integer.parseInt(times[1]);
   
        if(H>12&&M>0)
            int D = (H-11);
            while (D-->0)
                System.out.print("Dang");
            
        else if(H>12 && M==0)
            int D = (H-12);
            while (D-->0)
                System.out.print("Dang");
            
        
        else 
            System.out.println("Only "+time+".  Too early to Dang.");
        

    


L1-015 跟奥巴马一起画方块 (15 分)

import java.util.*;

public class Main 

	public static void main(String[] args) 
	
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		String str=scan.next();
		int a=0;
		if(n%2==0)
		
			a=n/2;
		
		else 
		
			a=n/2+1;  //四舍五入取整
		
		for (int i=0;i<a;i++)
		
			for(int j=0;j<n;j++)
			
				System.out.print(str);
			
			System.out.println();
		
		scan.close();
	



L1-016 查验身份证 (15 分)


这个也很简单,map即可

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Scanner;

public class Main 
    //这里就不用map了,用两个列表映射一下就行了
    
    public static void main(String[] args) 
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        ArrayList<String> res = new ArrayList<>();
        
        char[] chars =  '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' ;
        int[] index =  7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ;
        int n = scanner.nextInt();
        
        String[] str = new String[n];
        char[][] c = new char[n][18];
        
        
        for (int i = 0; i < n; i++) 
            str[i] = scanner.next();
            c[i] = str[i].toCharArray();
            int sum = 0;
            for (int j = 0; j < 17; j++) 
                try 
                    sum += Integer.parseInt((c[i][j] + "")) * index[j];
                 catch (Exception e) 
                    sum = -1;
                    break;
                
            
            if (sum == -1) 
                res.add(str[i]);
             else 
                sum %= 11;
                if (!(chars[sum] + "").equals((c[i][17]) + "")) 
                    res.add(str[i]);
                
            
        
        if (res.isEmpty()) 
            System.out.print("All passed");
         else 
            for (String ss : res) 
                System.out.println(ss);
            
        
    


L1-025 正整数A+B (15 分)

这题一定要注意输入细节
尤其是这样的输入:

12 58 sadawda

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

public class Main 
    //细节怪

	public static void main(String[] args) throws IOException 
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		String r1 = s.substring(0, s.indexOf(' '));
		String r2 = s.substring(s.indexOf(' ') + 1, s.length());
		String s1 = "", s2 = "", s3 = "";
		int n1 = 0, n2 = 0;
		try 
			int x1 = Integer.parseInt(r1);
			if (x1 < 1 || x1 > 1000) 
				s1 = "?";
				s3 = "?";
			
			n1 = x1;
		 catch (NumberFormatException e) 
			s1 = "?";
			s3 = "?";
		
		try 
			int x2 = Integer.parseInt(r2);
			if (x2 < 1 || x2 > 1000) 
				s2 = "?";
				s3 = "?";
			
			n2 = x2;
		 catch (NumberFormatException e) 
			s2 = "?";
			s3 = "?";
		
		System.out.print(s1.equals("") ? n1 + " + " : s1 + " + ");
		System.out.print(s2.equals("") ? n2 + " = " : s2 + " = ");
		System.out.println(s3.equals("") ? n1 + n2 : s3);
	




L1-019 谁先倒 (15 分)


这题咋说呢,都被给的测试集骗了

注意细节


import java.io.BufferedInputStream;
import java.util.Scanner;


import java.util.Scanner;

public class Main 
    //不能边来边判断,不然找不到的,那个测试集误导人!!

    public static void main(String[] args) 
        Scanner sc = new Scanner(System.in);
        int a = 0, b = 0;// 甲乙酒量
        int N = 0;// 划拳轮数
        a = sc.nextInt();
        b = sc.nextInt();
        N = sc.nextInt();
        int sum;
        int A_current_drink = 0, B_current_drink = 0;
        boolean flagA = false, flagB = false;
        int[][] drinking = new int[N][4];
        //初始化
        for (int i = 0; i < N; i++) 
            for (int j = 0; j < 4; j++) 
                drinking[i][j] = sc.nextInt();
            
        
        for (int i = 0; i < N; i++) 
            sum = drinking[i][0] + drinking[i][2];
            if (sum == drinking[i][1] && sum != drinking[i][3]) 
                A_current_drink++;
                if (A_current_drink > a) 
                    flagA = true;
                    break;
                
            
            if (sum == drinking[i][3] && sum != drinking[i][1]) 
                B_current_drink++;
                if (B_current_drink > b) 
                    flagB = true;
                    break;
                
            
        
        if (flagA) 天梯赛每日打卡02(7-12题解)

天梯赛每日打卡04(26-40题解)

天梯赛每日打卡05(41-45题解)

题解PTA团体程序设计天梯赛L1-024 后天 (5 分) Go语言|Golang

天梯赛题解 L1-049 天梯赛座位分配

PTA团体程序设计天梯赛-练习集 25分的题