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