SWEA 1288 새로운 불면증 치료법

1 개요[ | ]

SSWEA 1288 새로운 불면증 치료법

이거완전 sheep세기네(댓글 중에)

SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 2-3

2 C++[ | ]

#include<iostream>
using namespace std;
int main(int argc, char** argv)
{
	int test_case;
	int T;
	cin >> T;
	for (test_case = 1; test_case <= T; ++test_case) {
		int arr[10] = { 0 };
		int answer = 0;
		int input;
		scanf("%d", &input);
		int N = input;
		for (int i = 0; ; i++) {
			int temp = N;
			while (N != 0) {
				arr[N % 10] = 1;
				N /= 10;
			}
			int count = 0;
			for (int j = 0; j<10; j++) {
				if (arr[j] == 1) count++;
			}
			if (count == 10) {
				answer = temp;
				break;
			}
			N = input * i;
		}
		printf("#%d %d\n", test_case, answer);
	}
	return 0;
}

3 Java[ | ]

import java.util.*;
public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();

		int N, i, cur, temp, q;
		Set<Integer> seen = new HashSet<Integer>();

		for(int test_case = 1; test_case <= T; test_case++) {
			N = sc.nextInt();
			seen.clear();
			for(i=1; ; i++) {
				cur = N*i;
				for(temp=cur; temp>0; temp/=10) {
					q = temp%10;
					seen.add(q);
				}
				if(seen.size()>9) break;
			}
			System.out.format("#%d %d\n", test_case, cur);
		}
		sc.close();
	}
}

4 Python[ | ]

T = int(input())
for x in range(1, T+1):
    N = int(input())
    count = 0
    
    zero_to_nine = [str(i) for i in range(10)]
    while zero_to_nine:
        count += 1
        room = N * count
        room = str(room)

        for c in room:
            if c in zero_to_nine:
                zero_to_nine.remove(c)

    print('#{} {}'.format(x, room))

# github.com/wansang93/Algorithm
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}