일전에 뭐 게임 회사에서 본 간단한 퀴즈 테스트 입니다.
0~9까지의 문자로 된 숫자를 입력 받았을 때, 이 입력 값이 0~9까지의 숫자가 각각 한 번 씩만 사용된 것인지 확인하는 함수를 구하시오.
sample inputs: 0123456789 01234 01234567890 6789012345 012322456789
sample outputs: true false false true false
c언어입니다. 학교 과제용으로 풀었습니다..만 공유합니다.
#include <stdio.h>
int main() {
char MunNumber[12] = {0};
//11개 이상의 숫자가 입력된 경우 무조건 false, null문자까지 배열공간12
int NumChack[10] = {0};
char boolChack = 1;
printf("숫자를 0부터 9까지 하나씩 입력하세요. : ");
scanf("%s", MunNumber);
for(char i = 0; i <= 10 ; i++) {
for(char j = 0; j <= 10 ; j++) {
if(MunNumber[j] - 48 == i) NumChack[i] += 1;
//ASCII코드의 0~9값이 48~57이기 때문에 -48 해서 값을 숫자로 변환
//입력값중 i와 같은 값이 있을경우, NumChack[i]에 1을 더하기.
}
}
for(char i = 0; i <= 9 ; i++) {
if(NumChack[i] != 1) boolChack = 0;
//NumChack[]의 값 중 1이 아닌 값이 있을 경우 false
//(boolChack는 1로 초기화되어있음)
}
if(boolChack == 1) printf("true");
else printf("false");
return 0;
}
2018年05月02日 21:34
// 자바입니다
public static void main(String[] args) throws Exception {
String str = " 0123456789 01234 01234567890 6789012345 012322456789";
String[] nums = str.trim().split(" ");
for (int i=0; i<nums.length; i++) {
int[] numbers = new int[10];
for (int j=0; j<nums[i].length(); j++) {
numbers[nums[i].charAt(j)-48]++;
}
boolean flag = true;
for (int j=0; j<10; j++) {
if (numbers[j] != 1)
flag = false;
}
if (flag)
System.out.println(true);
else
System.out.println(false);
}
} // 배열에 해당하는 인덱스번째 ++ 시키고 다 1이여야만 트루를 출력하게했어요
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
char[] c = str.toCharArray();
for (char ch : c) {
if (!((ch >= 48 && ch <= 57) || ch == 32)) {
throw new Exception("format error");
}
}
String[] str2 = str.split(" ");
for (int i = 0; i < str2.length; i++) {
boolean test = true;
char[] ccc = str2[i].toCharArray();
for (int j = 1; j < ccc.length; j++) {
if (ccc[j-1] == ccc[j]) {
test = false;
break;
}
}
System.out.print(test + " ");
}
}
public class Duplicate_Numbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("0 ~ 9의 문자를 사용하여 입력해주세요: ");
String[] in = sc.next().split("");
ArrayList<String> temp = new ArrayList<String>(Arrays.asList(in));
int sum = 0;
Collections.sort(temp);
for (int i = 0; i < temp.size()-1; i++) {
if (temp.get(i).equals(temp.get(i+1))) {
sum++;
break;
}
}
if (sum > 0 || temp.size() != 10) {
System.out.println("false");
} else {
System.out.println("true");
}
}
}
저도 한줄 짜리!
list1 = '0123456789 01234 01234567890 6789012345 012322456789'.split()
def is_not_duplicate(str1):
return set(str1) == set("0123456789") and len(str1) == 10
for l in list1:
print(is_not_duplicate(l))
2018年05月23日 23:27
풀이 작성