diff --git a/code_study/Baekjoon/c/14626.c b/code_study/Baekjoon/c/14626.c new file mode 100644 index 0000000..d0a5c8f --- /dev/null +++ b/code_study/Baekjoon/c/14626.c @@ -0,0 +1,28 @@ +#include + +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; +} \ No newline at end of file diff --git a/code_study/Baekjoon/js/14626.js b/code_study/Baekjoon/js/14626.js new file mode 100644 index 0000000..f1feaaf --- /dev/null +++ b/code_study/Baekjoon/js/14626.js @@ -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; + } +} diff --git a/code_study/Baekjoon/python/14626.py b/code_study/Baekjoon/python/14626.py new file mode 100644 index 0000000..9b02040 --- /dev/null +++ b/code_study/Baekjoon/python/14626.py @@ -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 \ No newline at end of file