전체 글

문제 11576번: Base Conversion 타임머신을 개발하는 정이는 오랜 노력 끝에 타임머신을 개발하는데 성공하였다. 미래가 궁금한 정이는 자신이 개발한 타임머신을 이용하여 500년 후의 세계로 여행을 떠나게 되었다. 500년 후의 www.acmicpc.net 코드 My answer import sys a,b=map(int,sys.stdin.readline().split()) n=int(input()) num=0 word=list(map(int,sys.stdin.readline().split())) word.reverse() for idx,i in enumerate(word): num+=i*(a**idx) word=[] while(num!=0): r=num%b word.append(r) num//..
[-2진수]-2089번 2089번: -2진수 -2진법은 부호 없는 2진수로 표현이 된다. 2진법에서는 20, 21, 22, 23이 표현 되지만 -2진법에서는 (-2)0 = 1, (-2)1 = -2, (-2)2 = 4, (-2)3 = -8을 표현한다. 10진수로 1부터 표현하자면 1, 110, 111, 100, 101, 11010, 110 www.acmicpc.net My answer n=int(input()) tmp="" while(n!=0): if(n%(-2)!=0): n=n//(-2)+1 tmp+='1' else: n=n//(-2) tmp+='0' if(tmp==""): tmp+='0' print(tmp[::-1]) 더보기 -2진수라는 설명이 이해가 안가서 헷갈렸는데 그냥 2진수랑 똑같이 생각하는데 ..
[2진수 8진수]-1373번 My answer n='0b'+input() n = int(n, 2) print(oct(n)[2:]) Another answer print('%o'%int(input(),2)) 더보기 2진수로 변환할 때는 int()안에 2라는 인자도 넣어야 되는것도 다시 한번 알았고, 8진수로 변환하려면 oct()함수 말고도 %o 가 있다는걸 다시 한번 알았다. [8진수 2진수]-1212번 1212번: 8진수 2진수 첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다. www.acmicpc.net n=input() n = int(n, 8) print(bin(n)[2:])
[진법 변환2]-11005번 11005번: 진법 변환 2 10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 www.acmicpc.net My answer import sys import string tmp=list(map(int,sys.stdin.readline().split())) upper=[j for j in string.ascii_uppercase] table,result=dict(),"" for i in range(10,36): table[i]=upper[i-10] while(tmp[0]!=0): a=tmp[0]%tmp[1] tmp[0]=tmp[0]//t..
[GCD 합]-9613번 9613번: GCD 합 첫째 줄에 테스트 케이스의 개수 t (1 ≤ t ≤ 100)이 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있다. 각 테스트 케이스는 수의 개수 n (1 < n ≤ 100)가 주어지고, 다음에는 n개의 수가 주어진 www.acmicpc.net My answer import sys import itertools n,sums=int(input()),0 for i in range(n): tmp=list(map(int,sys.stdin.readline().split())) for j in itertools.combinations(tmp[1:], 2): a,b=max(j[0],j[1]),min(j[0],j[1]) while(b!=0): a=a%b a,b=b,a ..
[최대공약수]-1850번 1850번: 최대공약수 모든 자리가 1로만 이루어져있는 두 자연수 A와 B가 주어진다. 이때, A와 B의 최대 공약수를 구하는 프로그램을 작성하시오. 예를 들어, A가 111이고, B가 1111인 경우에 A와 B의 최대공약수는 1이고, A www.acmicpc.net Another answer import sys a,b=map(int,sys.stdin.readline().split()) if(b>a): a,b=b,a while(b!=0): a=a%b a,b=b,a print(a*'1') 더보기 우선 이 문제는 그냥 최대공약수 문제가 아니었다. 입력받은숫자만큼의 1로 구성된 두 수의 최대공약수를 구하는 문제였는데, 처음에는 예제만 보고 두 1로구성된숫자들의 1의개수의 차이 즉 맨처..
[최소공배수]-1934번 1934번: 최소공배수 두 자연수 A와 B에 대해서, A의 배수이면서 B의 배수인 자연수를 A와 B의 공배수라고 한다. 이런 공배수 중에서 가장 작은 수를 최소공배수라고 한다. 예를 들어, 6과 15의 공배수는 30, 60, 90등이 있 www.acmicpc.net My answer import sys n=int(input()) for i in range(n): a,b=map(int,sys.stdin.readline().split()) c=a*b while(b!=0): if(b>a): a,b=b,a a=a%b a,b=b,a print(c//a) Another answer import math for _ in[0]*int(input()): print(math.lcm(*map(int..
창빵맨
Let's be Developers