이 페이지는 코딩도장 데이터의 읽기 전용 정적 보관본입니다.

마에스트로

A는 세계의 이름난 작곡가다.

하지만 A는 시간이 갈 수록 작곡에 대한 아이디어와 열정이 조금씩 옅어지고 있었다.

그래서 아무렇게나 박자를 짓고 그 박자가 맞는지 확인해주게 하고 싶다.

그리고 당신은 그 프로그램을 만드는 일을 의뢰받았다.

<문제>

맨 처음 줄에 박자와 마디 수를 입력받는다.

그 다음 줄에 공백을 기준으로 음표를 입력한다.

최종결과를 COMPLETED와 The n bar is wrong 으로 출력하시오

예)

4/4 3
W QQH TQ.THTT

6/8 2
EES.S.SQ seWq

출력)

COMPLETED

2 BAR IS WRONG

-사용 할수 있는 음표의 종류

W = 온음표 H = 2분음표 Q = 4분음표 E = 8분음표 S = 16분음표 T = 32분음표

(점n분음표는 그 알파벳의 뒤에 점을 붙여주는 것으로 계산하며 점16분 음표까지만 된다.)

(쉼표는 그 쉼표의 박자에 대응 하는 음표의 소문자이다.)

2018/07/01 20:24

김영성

10개의 풀이가 있습니다.

어렸을 적 음악하던 때가 기억이 나서 푸는 내내 기분이 좋은 문제였습니다! 다만 결과에 있어 좀 차이가 있는데 확인해주시면 감사하겠습니다. 몇 가지 다른 예제를 덧붙여 놓습니다. 제가 틀린 내용이라면 지적 부탁드립니다~~

beat, num_node = input("박자, 마디 수:").split()
beat1, beat2 = map(int,beat.split('/'))
one_node = beat1/beat2
num_node = int(num_node)

nodes = input("음표:").split()

correct = []
if len(nodes) == num_node:
    for notes in nodes:
        count, temp = 0, 0
        for note in notes.upper():
            if 'W' == note:
                temp= 1
            elif 'H' == note:
                temp = 1/2
            elif 'Q' == note:
                temp = 1/4
            elif 'E' == note:
                temp = 1/8
            elif 'S' == note:
                temp = 1/16
            elif 'T' == note:
                temp = 1/32
            elif '.' == note:
                temp /= 2
            else :
                temp = 0
            count += temp
            #print(temp)
        correct.append(count == one_node)
        #print(notes, count)
    if correct.count(True) == num_node:
        print("COMPLETE")
    else:
        for i in range(num_node):
            if not correct[i] :
                print("{} BAR IS WRONG".format(i+1))
else :
    print('length is not correct')

## Output
# 박자, 마디 수:6/8 2
# 음표:EES.S.SH seWq
# 1 BAR IS WRONG
# 2 BAR IS WRONG
#
# 박자, 마디 수:4/4 3
# 음표:W QQH TE.THQEE
# 3 BAR IS WRONG
#
# 박자, 마디 수:3/4 3
# 음표:QQQ QH EEQEE
# COMPLETE
#
# 박자, 마디 수:4/4 3
# 음표:H.Q QQQEE  EEEEQ.E
# COMPLETE

2018/07/01 22:45

재즐보프

+1 감사합니다 - 김영성, 2018/07/01 23:01
note = {'W':'+1','H':'+1/2','Q':'+1/4','E':'+1/8','S':'+1/16','T':'+1/32','.':'*1.5'}
meter,bar = input('박자 마디: ').split()
score = input('음표: ').upper().split()

if len(score) != int(bar):
    mistake = True
    print("BAR's numbers are different")
for i in score:
    if eval(''.join(note[j] for j in i)) != eval(meter):
        mistake = True
        print('{} BAR is worng'.format(score.index(i)+1))
try: mistake
except: print('COMPLETED')

박자 마디: 4/4 3
음표: W QQH TE.THTT
3 BAR is worng

박자 마디: 6/8 2
음표: EES.S.SH seWq
1 BAR is worng
2 BAR is worng

박자 마디: 4/4 3
음표: Hh w H.Q
COMPLETED

2018/07/02 00:29

Creator

Python

dic = {"W": 1.0, "H": 1/2, "Q": 1/4, "E": 1/8, "S": 1/16, "T": 1/32}
b, m = input().split(' ')
b = int(b[0])/int(b[2])
e = input().split(' ')
flag = True
wrong = []
for i in range(int(m)):
    tmp_sum = 0
    for j in range(len(e[i])):
        if e[i][j] is '.':
            tmp_sum += dic[e[i][j-1]]*1/2
        elif e[i][j].islower():
            tmp_sum += dic[e[i][j].upper()]
        else:
            tmp_sum += dic[e[i][j]]
    if tmp_sum != b:
        flag = False
        wrong.append(i+1)
if flag:
    print("COMPLETED")
else:
    for i in wrong:
        print("{} BAR IS WRONG".format(i))

2018/07/02 17:28

Taesoo Kim

temp = input('tempo , bar : ').split()
Note = input('Note : ').split()
tempo,bar = eval(temp[0]), int(temp[1])
Notes = {'W':1, 'H':1/2, 'Q':1/4, 'E':1/8, 'S':1/16, 'T': 1/32}

for a in range(0,bar):
     test = tempo
     for b in range(0,len(Note[a])):
          x = Note[a][b].upper()
          if x in Notes:
               test -= Notes[x]
          else:
               test -= (Notes[Note[a][b-1]] * 1/2)
     if test == 0:
          Note[a] = True
     else:
          Note[a] = False

if False not in Note:
     print("COMPLETED")
for x in Note:
     if x == False:
          print("%d BAR IS WRONG" %(Note.index(x)+1))

2018/07/04 20:46

김영성

inputA = input('박자와 마디 수를 입력하세요: ')
inputB = input('음표를 입력하세요: ')

blankA = inputA.find(' ')
beat = eval(inputA[0:blankA])
count_bar = int(inputA[blankA+1:len(inputA)])
bar = inputB.split(' ')

def change_datatype_of_bar(bar):
    bar = bar.replace('W', '+1')
    bar = bar.replace('H', '+ (1/2)')
    bar = bar.replace('Q', '+ (1/4)')
    bar = bar.replace('E', '+ (1/8)')
    bar = bar.replace('S', '+ (1/16)')
    bar = bar.replace('T', '+ (1/32)')
    bar = bar.replace('.', '* (1.5)')

    return eval(bar)

result = ''
temp = 0

for i in range(count_bar):
    temp = change_datatype_of_bar(bar[i])
    if temp == beat:
        pass
    else:
        print('the', i+1 , 'bar is wrong')
        break
else:
    print('COMPLETE')

2018/07/06 02:47

서완길 (선인장물주기)

def bar_time(bar):
    note_times = {'W':1, 'H':1/2, 'Q':1/4, 'E':1/8, 'S':1/16, 'T':1/32}
    time = 0.0
    for i in range(len(bar)):
        if bar[i] != '.':
            time += note_times[bar[i]]
        else:
            time += note_times[bar[i-1]] / 2

    return time


def eval_music(input_str):
    line1, line2 = input_str.upper().split('\n')
    meter, bar_lst = eval(line1.split(' ')[0]), line2.split(' ')

    valid = True
    for i in range(len(bar_lst)):
        if bar_time(bar_lst[i]) != meter:
            print('BAR {} IS WRONG'.format(i + 1))
            valid = False

    if valid:
        print('COMPLETE')


eval_music('4/4 3\nW QQH TQ.THTT')
eval_music('6/8 2\nEES.S.SQ seWq')

2018/08/21 00:19

Noname

def Music(bakza, rhythm):
    madi = bakza.split()[1]
    bakza = bakza.split()[0].split('/')
    bakza = int(bakza[0])/int(bakza[1])

    rhythm = rhythm.split()
    count=0
    for i in rhythm:
        temp_total=0
        for j in range(len(i)):
            if i[j]=='W': temp=1
            elif i[j]=='H': temp=0.5
            elif i[j]=='Q': temp=0.25
            elif i[j]=='E': temp=0.125
            elif i[j]=='S': temp=0.0625
            elif i[j]=='T': temp=0.03125
            else: temp=0

            try:
                if i[j+1]=='.':
                    temp*=1.5
            except: 
                pass
            temp_total+=temp

        count+=1    
        if temp_total != bakza:
            return "The %s bar is wrong"%(count)

    return "Completed"


print(Music(input(),input()))

2019/02/04 13:30

얀차


tempo,nodes = input().split()
tempo_type = input().upper().split()
tempo1,tempo2 = map(int,tempo.split("/"))
beat = tempo1/tempo2

#Calculate tempo with note
def caltemp(i):
    node_map = {"W":1,"H":1/2,"Q":1/4,"E":1/8,"S":1/16,"T":1/32}
    count=0
    temp=0
    for j in i:
        if j == ".":
            count += temp/2
        else:
            count += node_map[j]
            temp = node_map[j]
    return count

#Calculate no for each node
result=[caltemp(i) for i in tempo_type]
#Create True/False table for each node
TF=[True if i == beat else False for i in result]

if False in TF:
    for i in range(len(TF)):
        if TF[i] == False:
            print("{} BAR IS WRONG".format(i+1))
else:
    print("COMPLETED")

2021/05/01 18:02

최태호

python 3.9입니다.

import sys

beat, num_node = input('박자와 마디 수를 입력하세요. ').split(' ')
beat = beat.split('/')
beat = int(beat[0]) / (int(beat[-1]) / 4)
num_node = int(num_node)
nodes = input('음표를 입력하세요. ').upper().split()
if len(nodes) != num_node: print('INVALID VALUE'); sys.exit()
node_table = {'W': 4, 'H': 2, 'Q': 1, 'E': 0.5, 'S': 0.25, 'T': 0.125, '.': 0}
n_num_list = []
for node in nodes:
    n_num = []
    for node_char in node:
        node_num = node_table[node_char]
        if node_num: n_num.append(node_num)
        else: n_num[-1] *= 1.5
    n_num_list.append(sum(n_num) == beat)
if not n_num_list.count(False): print('COMPLETED')
else:
    for bool_i in range(len(n_num_list)):
        if not n_num_list[bool_i]: print(f'{bool_i+1} BAR IS WRONG')

결과입니다.

박자와 마디 수를 입력하세요. 4/4 3
음표를 입력하세요. W QQH TQ.THTT
COMPLETED
박자와 마디 수를 입력하세요. 6/8 2
음표를 입력하세요. EES.S.SQ seWq
2 BAR IS WRONG

2021/07/31 11:40

이준우

using System;
using System.Collections.Generic;

namespace solution
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("\n 박자와 마디 수를 입력: ");
            string[] beatAndBar = Console.ReadLine().Split(' ');
            Console.Write("음표를 입력: ");
            int beat = int.Parse(beatAndBar[1]);
            string[] musicNote = Console.ReadLine().Split(' ');
            if (beat != musicNote.Length)
                Console.WriteLine("The {0} bar is wrong!!", beatAndBar[1]);
            else
            {
                string[] bSplit = beatAndBar[0].Split('/');
                checkBeat(float.Parse(bSplit[0]) / float.Parse(bSplit[1]), beat, musicNote);
            }
        }

        private static void checkBeat(float beat, int bar, string[] musicNote)
        {
            Dictionary<char, float> NthNote = new Dictionary<char, float>() 
            {{'W', 1f }, {'H', 1f/2 }, {'Q', 1f/4 },{'E', 1f/8 },{'S', 1f/16 },{'T', 1f/32 }, {'.', 3f/2 } };

            for (int n = 0; n < bar; n++)
            {
                float sum = 0f;
                for (int i = 0; i < musicNote[n].Length; i++)
                {
                    char c = char.ToUpper(musicNote[n][i]);
                    sum += NthNote[c];

                    if (i < musicNote[n].Length - 1 && musicNote[n][i + 1] == '.')
                    {
                        sum -= NthNote[c];
                        sum += (NthNote[c] * NthNote[char.ToUpper(musicNote[n][i + 1])]);
                        i += 1;
                    }
                }
                if (sum != beat)
                {
                    Console.WriteLine("The {0} bar is wrong!!", n + 1);
                    return;
                }
            }
            Console.WriteLine("COMPLETED");
        }
    }
}

2023/09/21 13:55

insperChoi

목록으로