20250629 baekjoon

This commit is contained in:
songyc macbook 2025-06-29 21:03:41 +09:00
parent f453e943e9
commit 65e53afb50
3 changed files with 66 additions and 0 deletions

View 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;
}

View 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;
}
}

View 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