import sys
input = sys.stdin.readline

def get_end_num(N):
    cnt = 0
    value = 0
    while True:
        if cnt == N:
            return value
        value +=1
        if "666" in str(value):
            cnt +=1

N = int(input())
value = get_end_num(N)
print (value)

 

import sys
input = sys.stdin.readline
N = int(input())
alphabets = []
alpha_dict = {}

for _ in range(N):
    alphabets.append(input().rstrip())

for alphabet in alphabets:
    square_root = len(alphabet) - 1
    for char in alphabet:
        if char in alpha_dict:
            alpha_dict[char] += pow(10, square_root)
        else:
            alpha_dict[char] = pow(10, square_root)        
        square_root -= 1

alpha_dict = sorted(alpha_dict.values(), reverse=True)
result, _max = 0, 9
for i in alpha_dict:
    result += i * _max
    _max -= 1
print (result)

 

#include <stdio.h>

int main(void)
{
	int A = 0;
	int B = 0;
	
	scanf("%d %d", &A, &B);
	
	if (A < B)
		printf("<");
	
	if (A > B)
		printf(">");
		
	if (A == B)
		printf("==");
		
	return 0;
}

 

import sys

def check_group_word(word):
    cache = []
    for i in word:
        if i in cache:
            if i == cache[-1]:
                pass
            else:
                return False
        else:
            cache.append(i)
    return True

if __name__ == "__main__":
    input = sys.stdin.readline
    N = int(input())
    cnt = 0
    for _ in range(N):
        word = input()
        bool = check_group_word(word)
        if bool:
            cnt +=1

    print (cnt)

 

import sys
from itertools import combinations
input = sys.stdin.readline
N, S = list(map(int, input().split()))
nums = list(map(int, input().split()))
cnt = 0
for i in range(1, len(nums)+1):
    result = combinations(nums, i)
    for num in result:
        if (sum(num) == S):
            cnt += 1
print (cnt)

 

 

합이 S만 되면 되기 때문에 순서성이 필요 없는 조합을 사용.

import sys
input = sys.stdin.readline
N = int(input())

words = []
for _ in range(N):
    words.append(input().strip('\n'))

words = list(set(words))
words.sort(key=lambda x: (len(x), x))
for i in words:
    print (i)

리스트 정렬할 때 sort의 파라미터로 lambda 식을 사용해서 정렬 기준들을 사용할 수 있음.

N, K = list(map(int, input().split()))
peoples = [i+1 for i in range(N)]
sequence = []
idx = K - 1
        
for _ in range(N):
    if idx < len(peoples):
        sequence.append(peoples.pop(idx))
        idx = idx + K - 1
    
    elif idx >= len(peoples):
        idx = idx % len(peoples)
        sequence.append(peoples.pop(idx))
        idx = idx + K - 1

print ("<", ', '.join(str(i) for i in sequence), ">", sep='')

처음에 조건문을 idx <= len(peoples), idx > len(peoples)로 해서 오답으로 나왔음.

idx랑 len(peoples)가 같은 경우는 인덱스 초과이기 때문.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int max = 0; 
	int temp = 0;
	bool flag = false;
	int arr[26] = { 0, };
	
	transform(s.begin(), s.end(), s.begin(), ::toupper); // 소문자화
	
	for (int i = 0; i < s.length(); i++)
		arr[int(s[i] - 65)] += 1;

	for (int i = 0; i < 26; i++)
	{
		if (arr[i] > max)
		{
			max = arr[i];
			temp = i;
		}
	}

	for (int i = 0; i < 26; i++)
	{
		if ((max == arr[i]) and (i != temp))
			flag = true;
	}

	if (flag)
		std::cout << "?" << endl;
	else
		std::cout << char(temp+65) << endl;

	return 0;
}
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
	string s;
	int cnt = 1;

	getline(cin, s);
	char delim = 0x20;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == delim)
			cnt = cnt + 1;
	}

	if (s[0] == delim)
		cnt--;

	if (s[s.length() - 1] == delim)
		cnt--;

	cout << cnt << endl;
	return 0;
}

 

import sys
input = sys.stdin.readline
x, y, w, h = list(map(int, input().split()))
print (min([x, w-x, h-y, y]))

최소값이 될 수 있는 경우는 크게 4가지가 있다. 경계선에 닿기만 하면 되는 최소 거리(직선)이므로 (x, y)에서 직선이 되는 경우 4가지 경우를 생각해서 최소값을 구하면 된다.

 

+ Recent posts