天天看點

北郵OJ 1005. 16校賽-Hawei Learning C 時間限制 1000 ms 記憶體限制 65536 KB

時間限制 1000 ms 記憶體限制 65536 KB

題目描述

    Hawei is learning C programming language recently, but he is so naive that he mistakes the  ∼  symbol in C for the  ¬  symbol in mathemetics. In math calculation, the answer to  ¬4  is the bitwise NOT of  (100)2 , ie.,  ¬(4)10=(011)2=(3)10 . Thus,  ¬4=3 . But in C programming, the compiler will explain calculation  ans=∼4  as the bitwise NOT of  (00000000000000000000000000000100)2  because  4  is a 32-bit integer, ie.,  ans=∼(00000000000000000000000000000100)2=(11111111111111111111111111111011)2 =(−5)10 .

    Unaware of this slight difference, Hawei checked for the bug for a whole day. When he finally found it, he was so angry that he decided to define two new functions  f(x)  and  G(x) . Function  f(x)  returns the answer of  ¬x , in other words, it is the bitwise NOT of  x since the most significant digit of  x . For instance, we have: 

     f((4)10)=f((100)2)=(011)2=(3)10

    , and

     f((22)10)=f((10110)2)=(01001)2=(9)10

    On the other hand, function  G(x)  is defined in following way:

北郵OJ 1005. 16校賽-Hawei Learning C 時間限制 1000 ms 記憶體限制 65536 KB

輸入格式

    The input starts with a single line containing an integer  T (1≤T≤10) , indicating the number of test cases.

For each test case, the first line contains one integers  N(1≤N≤100000 ), indicating the length of the string. The next lines contains a string  S , representing the integer  x  of the corresponding test case in its binary form. It is guaranteed that there is no leading zeroes in the input.

輸出格式

    For each test case, output a single line containing a 01 string, indicating the answer of  G(x)  in binary form. No leading zeroes are allowed.

輸入樣例

1
3
100
           

輸出樣例

1
           

找規律,統計輸入串中1的數量然後輸出相應數量的1即可

#include<cstdio>
#define N 100050
using namespace std;
int main(){
    int t,n,i;
    char str[N];
    for(scanf("%d",&t);t--;){
        scanf("%d",&n);
        scanf("%s",str);
        for(i=0;str[i];i++){
            if(str[i]=='1'){
                printf("1");
            }
        }
        printf("\n");
    }
    return 0;
}