UVA 213 Info Code! Simulation!

Source: Internet
Author: User

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!

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.