1048 digital encryption, C

If the title is to be noted that the number of bits less than the median number A, B, to make up 0 precedes B; B if the digital bits larger than A, it is not necessary to give up A 0, since the same results

#include <stdio.h>
int main()
{
	int i=0,j=0,flag=1,x=0,k=0;
	char a[101]={0},b[101]={0},c[101]={0};

	scanf("%s %s",a,b);
	while(a[i])	i++;
	i--;
	while(b[j])	j++;
    j--;
    
    if(j<i)   
	{
		x=i-j;		//如果b的位数少于a的位数,则需要在b前面补0
		while(k<x)
		{
			c[k] = '0'; 
			k++;       
		}
		//printf("%s|||||%s\n",b,c);
		strcat(c,b);
		//printf("%s|||||%s\n",b,c);
		strcpy(b,c);
		//printf("%s|||||%s\n",b,c);
		j = x+j;    //注意补0后,b末尾的位数也要变化
	}


	while(j!=-1)
	{
		if(i==-1)	break;

		if(flag%2)	//奇数
		{
			x = b[j]-'0'+a[i]-'0';
			x = x%13;
			if(x==10)		b[j]='J';
			else if(x==11)	b[j]='Q';
			else if(x==12)	b[j]='K';
			else			b[j]=x+'0';
		}
		if( (flag%2)==0 )	//偶数
		{
			x = b[j] - a[i];
			if(x<0)		x = x + 10;
			b[j] = x+'0';
		}

		j--;i--;flag++;
	}

    j=0;
    while(b[j]=='0')    j++;
	printf("%s",b+j);
   
	//system("pause");
	return 0;
}
Published 44 original articles · won praise 0 · Views 863

Guess you like

Origin blog.csdn.net/weixin_43916400/article/details/104615883