Generalized Matrioshkas UVA 11111

Source: Internet
Author: User

Talk about:

Test instructions is a large integer containing several small integers, and a small integer larger than a large integer. Also small integers may contain other small integers, and so on. Ask to determine if the entire containment relationship is correct. Just the description of the topic is not very clear. First, give you a sequence, for example:-9-7-2 2-3-1-2 2 1 3 7 9 where 9 is between 9 and 9 and contains only 7. If the sequence is-9-7 7-2 2 9 9 contains 7 and 22 numbers, which is obviously illegal. The solution is simply to build two stacks, one to store the input number, and the other to mark the inclusion of the integer will not be illegal.

Source:

#include <stdio.h> #define MAXN 10000000+5int stack[maxn];//store data int calculate[maxn];//tag data is reasonable int main () {  int p,wrong,val;  char c; Freopen ("Data", "R", stdin);  while (1) {   p=wrong=0;   do{    scanf ("%d%c", &val,&c);    if (val<0) {//Insert negative     stack[p]=calculate[p]=val;     p++;    }    else{//Insert Positive if     (stack[p-1]!=-val) {//If the top of the current stack does not match       wrong=1;     }     p--;     if (p-1>=0) {     calculate[p-1]+=val;//is not empty on the stack, modify     if (calculate[p-1]>=0) the stack for which the token data is reasonable      wrong=1 ;    }   }   } while (c!= ' \ n ');   if (Wrong| | p!=0)    printf (":-( Try again.\n ");   else     printf (":-) Matrioshka!\n ");   if ((C=getchar ()) ==eof) break    ;   else     ungetc (C,stdin);  }  return 0;}


Generalized Matrioshkas UVA 11111

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.