Good teacher (Nineth session of Hunan University computer Program Design Competition)

Source: Internet
Author: User

1334: Good teacher time limit: 1 Sec Memory Limit: MB
Submit: 267 Solved: 131
[Submit] [

id=1334 "style=" Color:rgb (26,92,200) ">status][

pid=1334 "style=" Color:rgb (26,92,200) ">web Board]

Description

I want to be a good teacher, so I decided to memorize all the students ' names. But soon I gave up, because there are so many students, I can't remember. But I can not let my students find this, otherwise it will be very embarrassing. So every time we call the student's name. I'll cite the students I know from his recent.

For example, there are 10 students:

A?? D?

? ? H?

?

When you want to call every student. The detailed term is:

Position

Called

1

A

2

Right of a (the classmate on the left)

3

Left of D (classmate of D)

4

D

5

Right of D (classmate of D)

6

Middle of D and H (students in the middle of D and H)

7

Left of H (classmate of H)

8

H

9

Right of H (classmate of H)

10

Right of the H (H right side of the classmate)

Input

Input has only one set of data. The first line is the number of students N (1<=n<=100). The second line is the name of each student, given in order from left to right. separated by a space.

Each name is either a no more than 3 English letters, or a question mark.

At least one student's name is not a question mark. The next line is the number of queries Q (1<=q<=100). Each set of data consists of an integer p (1<=p<=n), which is the position of the student to be called (the first of the left is position 1).

Output

For each of the inquiries. The output is termed. Note "Middle of X and Y" only have when the caller has two recent known students X and Y, and X is on the left side of Y.

Sample Input
10A?? D???

H??

438610

Sample Output
Left of Dhmiddle of D and hright of right of H

HINT

A water problem. Direct simulation, according to the location of the inference, output query, both sides of the search; ' Value.

#include <cstdio> #include <cstring>using namespace Std;int main () {char name[101][4];    int n,i,q,p,left,right;    scanf ("%d", &n);    for (i=1;i<=n;i++) scanf ("%s", Name[i]);    scanf ("%d", &q);        while (q--) {scanf ("%d", &p);        left=right=p;                if (name[p][0]!= '? ') printf ("%s\n", name[p]);//Direct is the location of the query else {while (1) {                if (left-1>0) left=left-1;                if (right+1<=n) right=right+1; if (name[left][0]!= '? ' && name[right][0]!= '? ')                    In two intermediate cases {printf ("middle of%s and%s\n", Name[left],name[right]);                Break } if (name[left][0]== '? ' && name[right][0]!= '? ') The situation on the left {for (i=1;i<=right-p;i++)//is also inferred here.                        May be on the left side of printf ("left of"); printf ("%s\n", Name[right]);                Break } if (name[left][0]!= '? ' && name[right][0]== '?)

'//On the right side of the situation {for (i=1;i<=p-left;i++) printf ("" ""); printf ("%s\n", Name[left]); Break }}}} return 0;}




Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Good teacher (Nineth session of Hunan University computer Program Design Competition)

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.