標籤:des style ar io os sp for on div
Alice and BobTime Limit: 1 Sec Memory Limit: 64 MB
Submit: 255 Solved: 43
DescriptionAlice is a beautiful and clever girl. Bob would like to play with Alice. One day, Alice got a very big rectangle and wanted to divide it into small square pieces. Now comes a problem: if all pieces of small squares are of the same size, how big could the squares be? To Alice, it‘s easy to solve the problem. However, she was very busy, so she asked Bob to help her. You know Alice is such a lovely girl and of course Bob won‘t refuse her request. But Bob is not so smart and he is especially weak in math. So he turns to you —a genius at programming. Alice will inform Bob the length and width of the big rectangle, and Bob have to tell her the longest length for the small square. All of these numbers are in their binary representations. InputThe first line of the input is a positive integer. This is the number of the test cases followed. Each test case contains two integer L and W in their binary representation which tells you the length and width of the very big rectangle(0< L , W < 2^1000 ).There may be one or several spaces between these integers.OutputThe output of the program should consist of one line of output for each test case. The output of each test case only contains the longest length for the small squares in its binary representation. No any redundant spaces are needed.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 還沒寫完