Codeforces #300 B Quasi Binary

Source: Internet
Author: User

Approximate test instructions: Given an integer, such as 32,32=11+11+10 ... Given an integer n, it can consist of integers consisting of 0 and 1, which requires a minimum of several such 0 and 1 integers. For example, 32 requires at least 3.

Parse: Treats the input integer as a string. For example, "s=" s[0]= ' 3 ', s[1]= ' 2 ';

So, let's do a two-dimensional array.  A[][]; Used to store this string s

For example, "32" is stored as

1 1

1 1

1 0

For example, 3451 storage is:

1 1 1 1

1 1 1 0

1 1 1 0

0 1 1 0

0 0 1 0

We just need to output this two-dimensional array in rows and ignore the leading 0.

The code is as follows:

#include <cstdio>#include<cstring>#include<iostream>#defineMax (A, b) a>b?a:busing namespacestd;inta[Ten][Ten];intMain () {strings; CIN>>s; intlen=s.size (); inti,j,k,cou=0;  for(i=0; i<len;i++) {cou=max (cou,s[i]-'0');  for(j=0; j<s[i]-'0'; j + +) A[j][i]=1;    }//stores the input n bitwise into a two-dimensional array a[][]; //For (i=0;i<cou;i++)//{    //For (j=0;j<len;j++)//printf ("%d", a[i][j]); //printf ("\ n"); // }printf"%d\n", cou);  for(i=0; i<cou;i++)    {        intflag=0;  for(j=0; j<len-1; j + +)            if(a[i][j]==1|| flag==1//Ignore leading 0 to output the elements in array a as rows. {Flag=1; printf ("%d", A[i][j]); } printf ("%d", A[i][j]); printf (" "); }    return 0;}

Many good treatments are not necessarily tied to numbers, but can also be treated as strings, reducing the difficulty of thinking.

Codeforces #300 B quasi Binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.