Alice and Bob 還沒寫完

來源:互聯網
上載者:User

標籤: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 還沒寫完

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.