일전에 뭐 게임 회사에서 본 간단한 퀴즈 테스트 입니다.
0~9까지의 문자로 된 숫자를 입력 받았을 때, 이 입력 값이 0~9까지의 숫자가 각각 한 번 씩만 사용된 것인지 확인하는 함수를 구하시오.
sample inputs: 0123456789 01234 01234567890 6789012345 012322456789
sample outputs: true false false true false
c# 입니다.
private void Form1_Load(object sender, EventArgs e)
{
String inputs = "0123456789 01234 01234567890 6789012345 012322456789";
String[] Split_input = inputs.Split(' ');
foreach (String s in Split_input)
{
if (Check_NUM(s))
Console.Write("true ");
else
Console.Write("false ");
}
}
private bool Check_NUM(String number)
{
List<Char> List_input = new List<Char>();
char[] data = number.ToCharArray();
foreach (Char d in data)
{
if (List_input.Contains(d))
return false;
List_input.Add(d);
}
if (List_input.Count == 10)
return true;
return false;
}
공백을 나눈 후 String을 Char 배열로 쪼개서 넣은다음 list클래스의 contain으로 값이 들어있는지 비교를 해보았습니다.
a = list(input("0~9까지 숫자를 한번씩 입력하시오 :"))
print ("True" if '0123456789' == "".join(sorted(a)) else "False")
2021年12月03日 13:27
(defn ^int to-int [^Character c]
(Character/getNumericValue c))
(let [FULLNUMBER 2r1111111111]
(defn ^boolean is-fullnumbers?
[^String numbers]
(loop [[x & xs] (map to-int numbers)
acc 2r0]
(let [is-fulled (= acc FULLNUMBER)]
(cond (nil? x) is-fulled
(and is-fulled x xs) false
:else
(let [shifted (bit-shift-left 1 x)]
(if-not (zero? (bit-and acc shifted))
false
(recur xs (bit-or acc shifted)))))))))
(time (map is-fullnumbers? ["0123456789" "01234" "01234567890" "6789012345" "012322456789"]))
;=> (true false false true false)
2015年10月02日 01:05
Swift로 간단하게 풀었습니다.
let answer = "0123456789".utf8.reduce(0) { 0ドル + Int(1ドル) }
let input = ["0123456789", "01234", "01234567890", "6789012345", "012322456789"];
let output = input.map { 0ドル.utf8.reduce(0) { 0ドル + Int(1ドル) } == answer }
print(output) // [true, false, false, true, false]
2015年10月07日 02:03
box=range(0,10) values=raw_input("> ") for i in values: box.remove(int(i)) if box: print 'false!' else: print 'true!'
2016年12月05日 00:17
int main() { int i; int a[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; char c[256]; fgets(c, sizeof(c), stdin); c[strlen(c)-1] = '0円';
if (strlen(c) != 10) {
printf("False\n");
return 0;
}
for (i = 0; i < 10; i++) {
a[(int)(c[i])-48]++;
}
for (i = 0; i < 10; i++) {
if (a[i] != 1) {
printf("False\n");
return 0;
}
}
printf("True\n");
return 0;
}
2016年12月13日 13:12
//이게 레벨이 1이...????
using namespace std;
int main() { int innum; string firstin; int count; bool flag; int num[10] = { 0 };
cout << "숫자 입력 >> ";
cin >> firstin;
int coutn = 0;
innum = stoi(firstin);
count = 0;
flag = 0;
for (int ws = innum;;)
{
coutn++;
if(ws != 0) num[ws % 10]++;
if (ws < 10) break;
ws /= 10;
}
for (int i = 0; i < coutn-1; i++)
{
if (firstin[i] == '0') num[0]++;
}
for (int i = 0; i < 10; i++)
{
cout << "num[" << i << "] = " << num[i] << endl;
if (num[i] != 1) flag = 1;
}
if (flag) cout << "false" << endl;
else cout << "ture" << endl;
}
2017年03月25日 15:25
풀이 작성