北邮OJ 1005. 16校赛-Hawei Learning C
時間限制?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?xsince 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:
輸入格式
?? ?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; }
總結
以上是生活随笔為你收集整理的北邮OJ 1005. 16校赛-Hawei Learning C的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北邮OJ 981. 16校赛-Saber
- 下一篇: 北邮OJ 1010. 16校赛-Bina