[BOJ] Bronze IV 부수기: 열일곱번째 날
- 코딩 초보. 효율적인 코드 구현이 아닐 수 있습니다.
- 구현언어: Python , C99
- 푼 문제: 5893,5928,6763,6764,6778
- 못 푼 문제: 0개
5893. 17배
상근이는 이진수 곱셈에 어려움을 겪는 여자친구를 위한 프로그램을 만들려고 한다.
상근이의 여자친구는 항상 이진수에 17을 곱한다. 즉, 이진수 N이 입력으로 들어오면 17을 곱한 다음 이진수로 출력하는 프로그램을 작성하시오.
1.C99
#include <stdio.h>
#include <string.h>
char N[1001];
char mulN[1006];
int len;
int i,j,k,t;
int main()
{
gets(N);
len=strlen(N);
strcpy(mulN, N);
for(i=len; i<len+4; i++)
mulN[i]='0';
j=i-1;
k=0;
for(i=len-1; j>=0; i--,j--)
{
t=k+(i<0?'0':N[i])+mulN[j]-'0'*2;
mulN[j]=t%2+'0';
k=t/2;
}
if(k) printf("1");
puts(mulN);
return 0;
}
c언어로 1000자리의 n을 입력받으므로 이러면 long long 타입을 사용해도 값을 모두 표현할 수 없기 떄문에, 문자열을 사용하여 바꾸어줘야한다. 위는 yy2598님의 만점짜리 코드를 가져와봤다. (참고용) 아직 이해를 못했다. 천천히 봐야지.
2.Python
n=input()
n=int(n,2)*17
print(bin(n)[2:])
파이썬 만만세다. (bin()을 사용할때, 출력하면 0b어쩌고저쩌고...이런식으로 나와서 오로지 이진수만 출력되도록 하기 위해서는 [2:]로 출력하도록 설정해주어야 한다.
5928. Contest Timing
Bessie the cow is getting bored of the milk production industry, and wants to switch to an exciting new career in computing. To improve her coding skills, she decides to compete in the on-line USACO competitions. Since she notes that the contest starts on November 11, 2011 (11/11/11), she decides for fun to download the problems and begin coding at exactly 11:11 AM on 11/11/11.
Unfortunately, Bessie's time management ability is quite poor, so she wants to write a quick program to help her make sure she does not take longer than the 3 hour (180 minute) time limit for the contest. Given the date and time she stops working, please help Bessie compute the total number of minutes she will have spent on the contest.
1.Python
d,h,m=map(int,input().split())
a=d*24*60+h*60+m
b=11*24*60+11*60+11
c=a-b
if c<0:
print(-1)
else:
print(c)
단순 사칙연산 문제라 c언어 구현은 생략.
6763. Speed fines are not fine!
The input will be two integers. The first line of input will be speed limit. The second line of input will be the recorded speed of the car.
If the driver is not speeding, the output should be:
Congratulations, you are within the speed limit!
If the driver is speeding, the output should be:
You are speeding and your fine is $F.
where F is the amount of the fine as described in the table above.
1.Python
a=int(input())
b=int(input())
if a<b:
if (b-a>=1 and b-a<=20):
print("You are speeding and your fine is $100.")
elif (b-a>=21 and b-a<=30):
print("You are speeding and your fine is $270.")
else:
print("You are speeding and your fine is $500.")
else:
print("Congratulations, you are within the speed limit!")
마찬가지로 단순 조건문 문제라(구현에 큰 차이 없을듯) c언어 구현 생략.
6764. Sounds Fishy!
A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a fish is swimming past if:
- there are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we will call “Fish Rising”), or
- there are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we will call “Fish Diving”), or
- there are four consecutive depth readings which are identical (which we will call “Constant Depth”).
All other readings will be considered random noise or debris, which we will call “No Fish.”
Your task is to read a sequence of depth readings and determine if the alarm will sound.
1.Python
depth=[]
for i in range(4):
k=int(input())
depth.append(k)
if(depth[0]<depth[1] and depth[1]<depth[2] and depth[2]<depth[3]):
print("Fish Rising")
elif (depth[0]>depth[1] and depth[1]>depth[2] and depth[2]>depth[3]):
print("Fish Diving")
elif max(depth)==min(depth):
print("Fish At Constant Depth")
else:
print("No Fish")
6778.Which Alien?
Canada Cosmos Control has received a report of another incident. They believe that an alien has illegally entered our space. A person who witnessed the appearance of the alien has come forward to describe the alien’s appearance. It is your role within the CCC to determine which alien has arrived. There are only 3 alien species that we are aware of, described below:
- TroyMartian, who has at least 3 antenna and at most 4 eyes;
- VladSaturnian, who has at most 6 antenna and at least 2 eyes;
- GraemeMercurian, who has at most 2 antenna and at most 3 eyes.
1.Python
a=int(input())
e=int(input())
if (a>=3 and e<=4):
print("TroyMartian")
if (a<=6 and e>=2):
print("VladSaturnian")
if(a<=2 and e<=3):
print("GraemeMercurian")
단순 조건문 문제다.
'💻STUDY > BOJ' 카테고리의 다른 글
[BOJ] 1546. 평균 (C, Python3) (0) | 2022.01.14 |
---|---|
[BOJ] 1157. 단어 공부 (C) (0) | 2022.01.14 |
[BOJ] 1152. 단어의 개수 (0) | 2022.01.12 |
[BOJ] Bronze IV 부수기: 열여섯번째 날 (0) | 2022.01.11 |
[BOJ] Bronze IV 부수기: 열다섯번째 날 (0) | 2022.01.10 |
댓글