#include<stdio.h>
#include<string.h>
int main(){
char a[101]={0},tempb[101]={0},b[101]={0},lst[14]="0123456789JQK";
int len1,len2,i;
scanf("%s %s",a,tempb);
len1=strlen(a);
len2=strlen(tempb);
if(len1>len2){
memset(b, '0', len1-len2);
len2=len1;
}
strcat(b,tempb);
for(i=1;i<=len1;i++){
if(i%2==0)
b[len2-i]=(b[len2-i]-a[len1-i]+10)%10;
if(i%2==1)
b[len2-i]=(b[len2-i]-'0'+a[len1-i]-'0')%13;
}
for(i=0;i<len2;i++){
if(i<len2-len1)
printf("%c",b[i]);
else
printf("%c",lst[b[i]]);
}
return 0;
}
总结:
1、本题代码参考
http://blog.youkuaiyun.com/plank_root/article/details/51703035
很厉害!
2、用到了memset:
void *memset(void *s, int ch, size_t n);
函数解释:将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 ch 替换并返回 s 。
memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法 。(来自百度百科)
3、lst[14]=”0123456789JQK”的使用,简化了很多选择打印的语句。