Background: one ac!! And the commissioning time is also short!!! It seems that this custom function is really a good way!! The concept is clear, debugging and clear!
Idea: Some single function is piled up, each function has its own function.
Learning: 1. I use the analog hand binary as a decimal method, and the method given in the small purple book seems simpler: (This seems to reveal the method of converting ordinary numbers except for the number of strings) (ordinary binary number, converted to decimal number on a single split)
Assumpt that temp[] has n charnumbersint decimal=0;for (int i = 0;i < n;i++) { decimal=decimal*2 +temp[i]-' 0 ';}
#include <stdio.h> #include <math.h>char list[248],temp[8],answer[10000];char scan (void) {int count=0; Char A;while ((a = GetChar ())! = EOF && A! = ' \ n ') {list[count++] = A;} return A;} void print (int x,int n) {int y;if (n = = 1) y=0;else if (n = = 2) Y=1+x;else if (n = = 3) Y=4+x;else if (n = = 4) y=11+x;else if (n = = 5) Y=26+x;else if (n = = 6) Y=57+x;else if (n = = 7) y=120+x;printf ("%c", List[y]);} void get (int length) {char a;int count=0;for (int i = 0;i < length;i++) {if (a = GetChar ()) = = ' \ n ') {i--;} else{temp[count++] = A;}}} int calculate (int n) {int ans=0;for (int i = N-1,k = 0;i >= 0;i--, k++) {ans+= (temp[i]-' 0 ') * (int) POW (2.0, (double) k);} return ans;} BOOL Make (void) {get (3), if (temp[0] = = ' 0 ' && temp[1] = = ' 0 ' && temp[2] = = ' 0 ') {printf ("\ n"), return true; int N=calculate (3), while (1) {get (n), bool over = false;for (int i = 0;i < n;i++) if (temp[i]! = ' 1 ') over =true;if (!over) {/ /this Segmentbreak;} int a = calculate (n);p rint (a,n); }return false;} int main (void) {WHILe (Scan ()!=eof) {while (1) if (make ()) is break; GetChar (); } return 0;}
UVA 213 Info Code! Simulation!