【PTA】String connection and price reduction reminder robot

Please add image description
Personal business card:

blogger: Alcoholics ᝰ.
Personal profile: Indulge in wine, and strive for a future with a drink.
column: PTA exercises and analysis
introduce: Recorded the blogger's practice questions in pta

Please add image description

foreword

1 Introduction

"PTA programming experimental auxiliary teaching platform" is an auxiliary teaching platform for programming courses led by Zhejiang University, managed and operated by Hangzhou Baiteng Education Technology Co., Ltd., and jointly constructed by teachers in colleges and universities across the country. At present, 538 colleges and universities across the country have participated, and 3,152 teachers have jointly constructed 66,095 high-quality topics, and the number of registered students has reached 1.36 million; there are 14 fixed topic sets (covering C language, JAVA language, Python language, data structure, database system) and China University Computer Competition Question Bank) and 55 professional course topic sets (covering computer, electronics, literature, foreign language and Huawei certification). There are 10 types of questions including true and false questions, fill-in-the-blank questions, multiple-choice questions, multiple-choice questions, program fill-in-the-blank questions, function questions, programming questions, subjective questions, multi-file programming questions and SQL programming questions.

2. Advantages

  • Support 200,000 people online at the same time
  • Support multiple question types
  • Support a variety of judgment modes
  • Provide comprehensive guarantee for teaching quality
  • Instant question answering system

1. String concatenation

1. Topics

This question requires writing a program that uses pointers to connect two strings (the strcat function cannot be used), and outputs the connected strings.

Input format:
Enter a non-empty string terminated by a carriage return (no more than 40 characters), and then enter a non-empty string terminated by a carriage return (no more than 40 characters).

Output format:
One line outputs the new string after the two strings are concatenated.

Input sample:

Beijing_
China

Sample output:

Beijing_China

Code Length Limit 16 KB
Time Limit 400 ms
Memory Limit 64 MB

2. Code

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        System.out.println(str1+str2);
    }
}

Second, the price reduction reminder robot

1. Topics

Little T has been wanting to buy a toy for a long time, but the price is a little high. He plans to wait until it is cheaper to buy it. But staring at the shopping website every day is very troublesome. Please help Xiao T to write a price reduction reminder robot, which will send a reminder when the current price of the toy is cheaper than the price he set.

Input format:
The first line of input is two positive integers N and M (1≤N≤100, 0≤M≤1000), indicating that there are N price records, and the price set by small T is M.

The next N lines, each with a real number Pi (−1000.0 < Pi < 1000.0), represent a price record.

Output format:
For each price record P that is cheaper than the set price M, output On Sale! P in one line, where P is output to 1 decimal place.

Input sample:

4 99
98.0
97.0
100.2
98.9

Sample output:

On Sale! 98.0
On Sale! 97.0
On Sale! 98.9

Code Length Limit 16 KB
Time Limit 600 ms
Memory Limit 64 MB

2. Code

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        double[] num = new double[N];
        for (int i = 0; i < N; i++) {
    
    
            num[i] = sc.nextDouble();
        }
        for (int i = 0; i < N; i++) {
    
    
            if (num[i] < M){
    
    
                System.out.println("On Sale! " + num[i]);
            }
        }

    }
}

Guess you like

Origin blog.csdn.net/m0_65144570/article/details/127098569