20250629 baekjoon
This commit is contained in:
parent
f453e943e9
commit
65e53afb50
28
code_study/Baekjoon/c/14626.c
Normal file
28
code_study/Baekjoon/c/14626.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char isbn[14];
|
||||||
|
scanf("%s",isbn);
|
||||||
|
int chk_num = isbn[12]-'0';
|
||||||
|
int acc=0, dmg_weight;
|
||||||
|
for(int i=0; i<12; i++) {
|
||||||
|
if(isbn[i] != '*') {
|
||||||
|
if(i%2==0) acc += isbn[i] - '0';
|
||||||
|
else acc += 3*(isbn[i] - '0');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(i%2==0) dmg_weight = 1;
|
||||||
|
else dmg_weight = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int res = 0;
|
||||||
|
while(1) {
|
||||||
|
if((chk_num + acc + (dmg_weight*res))%10 == 0 ) {
|
||||||
|
printf("%d\n",res);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
res++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
code_study/Baekjoon/js/14626.js
Normal file
21
code_study/Baekjoon/js/14626.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
let input = require("fs").readFileSync(0, "utf8").toString().trim().split('');
|
||||||
|
let dmg_weight;
|
||||||
|
const chk_num = Number(input.splice(12)[0]);
|
||||||
|
const acc = input.reduce((acc,v,i) => {
|
||||||
|
if(v !== '*') {
|
||||||
|
if(i%2 === 0) return acc += Number(v);
|
||||||
|
else return acc += 3*Number(v);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(i%2 === 0) dmg_weight = 1;
|
||||||
|
else dmg_weight = 3;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
},0);
|
||||||
|
|
||||||
|
for(let i=0; i<10; i++) {
|
||||||
|
if((i*dmg_weight + acc + chk_num)%10 === 0) {
|
||||||
|
console.log(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
code_study/Baekjoon/python/14626.py
Normal file
17
code_study/Baekjoon/python/14626.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
isbn = input()
|
||||||
|
acc = 0
|
||||||
|
isOdd = False
|
||||||
|
for n in isbn[:12] :
|
||||||
|
isOdd = not isOdd
|
||||||
|
if n != '*' :
|
||||||
|
if isOdd :
|
||||||
|
acc += int(n)
|
||||||
|
else :
|
||||||
|
acc += 3*int(n)
|
||||||
|
else :
|
||||||
|
weight = 1 if isOdd else 3
|
||||||
|
|
||||||
|
for i in range(10) :
|
||||||
|
if (i*weight + acc + int(isbn[12]))%10 == 0 :
|
||||||
|
print(i)
|
||||||
|
break
|
||||||
Loading…
x
Reference in New Issue
Block a user