[백준/Java] 10430 : 나머지

SEOP·2023년 4월 24일
0

import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        System.out.println((a+b)%c);
        System.out.println(((a%c)+(b%c))%c);
        System.out.println((a*b)%c);
        System.out.println(((a%c)*(b%c))%c);
    }
}

OR

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write(String.valueOf((a+b)%c));
        bw.newLine();
        bw.write(String.valueOf(((a%c)+(b%c))%c));
        bw.newLine();
        bw.write(String.valueOf((a*b)%c));
        bw.newLine();
        bw.write( String.valueOf((a%c) * (b%c)%c ));
        bw.flush();
        bw.close();
    }
}
profile
응애 나 애기 개발자

0개의 댓글