POJ C Programming Advanced Programming Question # #: Queued Games

Source: Internet
Author: User

Programming Question # # #: Queued Games

Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )

Note: Total time limit: 1000ms memory limit: 65536kB

Describe

In kindergarten, the teacher arranges children to do a line-up game. First, the teacher carefully arranged the same number of small boys and young girls in a queue, each child according to their position in the queue to send a number (numbering starting from 0). Then the teacher told the children, standing in front of the little boy can and behind him next to the little girl hand out of the queue, the rest of the children to stand up, and then the next small boys and girls in hand to leave the queue, so back and forth. Thanks to the careful arrangement of the teachers, it is possible to ensure that every two children can leave the queue in hand, and the last two children left are the smallest and the largest two children. (Note: Only the little boy is in front, the little girl is behind, and there are no other children between them, they can leave the queue in hand). According to the teacher's line-up, according to the little girl number from small to large order, give all hands in hand to leave the queue of little boy and little girl number pair.

Input

Represents a child queue with a string. Only two characters are present in the string, representing the little boy and the little girl, the first character representing the little boy, and the other character representing the little girl. The total number of children does not exceed 100

Output

By the little girl number sequence, sequentially output the number pair of the little boy and the little girl who left the queue, each line a pair of numbers, separated by a space between the numbers.

Sample input

((()(())())(()))

Sample output

2 3

5 6

4 7

8 9

1 10

12 13

11 14

0 15

#include <iostream>#include<stdio.h>using namespacestd;intMain () {CharBoy , temp; intEnd =0, num =0; Chara[ -]; scanf ("%c", &Boy ); a[0] =0;  while(SCANF ("%c", &temp)! =EOF) {        if(temp = =Boy ) {End++; Num++; A[end]=num; }        Else{num++; printf ("%d%d\n", a[end], num); End--; if(End <0)return 0; }    }    return 0;}

POJ C Programming Advanced Programming Question # #: Queued Games

Related Article

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.