首页 > 代码库 > Alice and Bob 还没写完
Alice and Bob 还没写完
Alice and BobTime Limit: 1 Sec Memory Limit: 64 MB
Submit: 255 Solved: 43
Description
Input
Output
Sample Input
2100 1000100 110
Sample Output
10010
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void mult(int p[],int *len1)
{
int i;
for(i=0;i<*len1;i++)
{
p[i]*=2;
p[i+1]+=p[i]/10;
p[i]%=10;
printf("p[%d]=%d\n",i,p[i]);
}
if(p[i])
(*len1)++;
}
void add(int p[],int q[],int *len1)
{
int i;
for(i=0;i<*len1;i++)
{
p[i]+=q[i];
if(p[i]>9)
{
p[i]-=10;
p[i+1]++;
}
}
if(p[i])
(*len1)++;
}
int main() //transfer binary to dimcal ,convey double"长度,十进制的数组"
{
freopen("a.txt","r",stdin);
int n,i,j;
char str1[1001];
char str2[1001];
int num_a[1000];
int num_b[1000];
int num_c[1000]; //两次出始化
int len1,len2;
scanf("%d",&n);
while(n--)
{
scanf("%s",str1);
scanf("%s",str2);
len2=len1=1;
memset(num_a,0,sizeof(num_a));
memset(num_b,0,sizeof(num_b));
memset(num_c,0,sizeof(num_c));
for(i=0;str1[i]!=‘\0‘;i++)
{
num_c[0]=str1[i]-‘0‘;
mult(num_a,&len1); //乘2
add(num_a,num_c,&len1);
}
for(i=0;str2[i]!=‘\0‘;i++)
num_a[i]=str2[i]-‘0‘;
}
return 0;
}
Alice and Bob 还没写完