"SWEA 2029 몫과 나머지 출력하기"의 두 판 사이의 차이

37번째 줄: 37번째 줄:
     }
     }
}
}
</source>
==Python==
<source lang='python'>
#kcy
k = int(input())
for i in range(0, k):
    a, b = map(int, input().split())
       
    print("#%d" % (i+1), end=' ')
    print(int(a/b), a%b)
</source>
</source>

2019년 11월 6일 (수) 10:50 판

1 개요

SWEA 2029 몫과 나머지 출력하기
  • a를 b로 나눈 몫(a/b)과 a를 b로 나눈 나머지(a%b)를 출력한다.
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-2

2 C++

#include <iostream>
using namespace std;
int main() {
    int T;
    cin >> T;
    for(int tc=1; tc<=T; tc++) {
        int a, b;
        cin >> a;
        cin >> b;
        cout << "#" << tc << " " << a/b << " " << a%b << endl;
    }
}

3 Java

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=1; t<=T; t++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.format("#%d %d %d\n", t, a/b, a%b);
        }
    }
}

4 Python

#kcy

k = int(input())

for i in range(0, k):
    a, b = map(int, input().split())
        
    print("#%d" % (i+1), end=' ')
    print(int(a/b), a%b)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}