HackerLand University has the following grading policy:

  • Every student receives a  in the inclusive range from  to .
  • Any  less than  is a failing grade.

Sam is a professor at the university and likes to round each student's  according to these rules:

  • If the difference between the  and the next multiple of  is less than , round  up to the next multiple of .
  • If the value of  is less than , no rounding occurs as the result will still be a failing grade.

For example,  will be rounded to  but  will not be rounded because the rounding would result in a number that is less than .

Given the initial value of  for each of Sam's  students, write code to automate the rounding process. For each , round it according to the rules above and print the result on a new line.

Input Format

The first line contains a single integer denoting  (the number of students). 
Each line  of the  subsequent lines contains a single integer, , denoting student 's grade.

Constraints

Output Format

For each  of the  grades, print the rounded grade on a new line.

Sample Input 0

4
73
67
38
33

Sample Output 0

75
67
40
33

Explanation 0

image

  1. Student  received a , and the next multiple of  from  is . Since , the student's grade is rounded to .
  2. Student  received a , and the next multiple of  from  is . Since , the grade will not be modified and the student's final grade is .
  3. Student  received a , and the next multiple of  from  is . Since , the student's grade will be rounded to .
  4. Student  received a grade below , so the grade will not be modified and the student's final grade is .

 

Given a time in -hour AM/PM format, convert it to military (-hour) time.

Note: Midnight is  on a -hour clock, and  on a -hour clock. Noon is  on a -hour clock, and  on a -hour clock.

Input Format

A single string containing a time in -hour clock format (i.e.:  or ), where  and .

Output Format

Convert and print the given time in -hour format, where .

Sample Input

07:05:45PM

Sample Output

19:05:45

 

Colleen is turning  years old! Therefore, she has  candles of various heights on her cake, and candle  has height . Because the taller candles tower over the shorter ones, Colleen can only blow out the tallest candles.

Given the  for each individual candle, find and print the number of candles she can successfully blow out.

Input Format

The first line contains a single integer, , denoting the number of candles on the cake. 
The second line contains  space-separated integers, where each integer  describes the height of candle .

Constraints

Output Format

Print the number of candles Colleen blows out on a new line.

Sample Input 0

4
3 2 1 3

Sample Output 0

2

Explanation 0

We have one candle of height , one candle of height , and two candles of height . Colleen only blows out the tallest candles, meaning the candles where . Because there are  such candles, we print  on a new line.

 

 

 


두번 for문 쓰지 않고


한번에 비교하면서 카운트 하기 


(max 변화시 sum 다시 1로 초기화)



  public static void main(String[] args) {

  

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        

        int max = 0;

        int sum = 0;

        int num;

        

        for(int i =0; i < n; i++){

            num = in.nextInt();

            

            if(num > max){

                sum = 1;

                max = num;

            }else if(num == max){

                sum++;

            }

        }

        System.out.println(sum);

    }


Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Input Format

A single line of five space-separated integers.

Constraints

  • Each integer is in the inclusive range .

Output Format

Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than 32 bit integer.)

Sample Input

1 2 3 4 5

Sample Output

10 14

Explanation

Our initial numbers are , and . We can calculate the following sums using four of the five integers:

  1. If we sum everything except , our sum is .
  2. If we sum everything except , our sum is .
  3. If we sum everything except , our sum is .
  4. If we sum everything except , our sum is .
  5. If we sum everything except , our sum is .

As you can see, the minimal sum is  and the maximal sum is . Thus, we print these minimal and maximal sums as two space-separated integers on a new line.

Hints: Beware of integer overflow! Use 64-bit Integer.


 



복잡하게 품..


밑에 처럼 최대 최소값을 함수로 찾고 


최대 최소값 뺀 후 더하는 것 보다 


sum에서 빼는게 빠르다!!!!




        long sum = 0;

        long min = Long.MAX_VALUE;

        long max = Long.MIN_VALUE;

        

        Scanner scanner = new Scanner(System.in);

        for (long i = 0; i < 5; i++) {

            long n = scanner.nextLong();

            sum += n;

            min = Math.min(n, min);

            max = Math.max(n, max);

        }

        System.out.println((sum - max)+" "+(sum - min));






Consider a staircase of size :

   #
  ##
 ###
####

Observe that its base and height are both equal to , and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size .

Input Format

A single integer, , denoting the size of the staircase.

Output Format

Print a staircase of size  using # symbols and spaces.

Note: The last line must have  spaces in it.

Sample Input

6 

Sample Output

     #
    ##
   ###
  ####
 #####
######

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of .

 


+ Recent posts