// 2017复试第2题.cpp : 定义控制台应用程序的入口点。
/* 给定一个9位数字的ISBN,求其校验位。ISBN格式为2-02-033598,
校验位的计算方法如下:从左到右依次将各位数字乘10,9,8,……,2,求出其和S,作模运算得M=S mod 11。
若11-M在1和9之间,校验位即为该数字;
若11-M等于10,校验位为X;11-M等于11,校验位为0。输出添加校验位的ISBN,如2-02-033598-0。*/
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char a[12];
int s = 0;
int i; int t = 0;
for(i = 0;i<11;i++){
scanf("%c",&a[i]);
if(a[i] >= '0' && a[i] <= '9'){
s += (a[i] - '0') * (10-t);
t++;
}
}
int m = s % 11;
char y;
if(11- m == 10){
y = 'x';
}else if(11 - m == 11){
y = '0';
}else{
y = (11-m) + '0';
}
//printf("%s-%c\n",a,y);
for(int i = 0;i<11;i++){
printf("%c",a[i]);
}
printf("-%c\n",y);
system("pause");
return 0;
}