Good Teacher (Computing Program Design Competition for the ninth Hunan University Student)

Source: Internet
Author: User

1334: Good Teacher Time Limit: 1 sec memory limit: 128 MB
Submit: 267 solved: 131
[Submit] [Status] [web board] Description

I want to be a good teacher, so I decided to remember the names of all the students. But soon I gave up, because there were too many students to remember. However, I cannot allow my students to find this point, otherwise it will be very shameless. So every time I call a student's name, I will reference the student closest to him. For example, there are 10 students:

A? ? D? ? ? H? ?

When you want to call each student, the specific name is:

Location

Name

1

A

2

Right of a (student on the right of)

3

Left of D (students on the left of D)

4

D

5

Right of D (student on the right)

6

Middle of D and H (students between D and H)

7

Left of H (students on the left of H)

8

H

9

Right of H (h)

10

Right of right of H (h)

 

Input

Only one group of data is input. The first row is the number of students n (1 <=n <= 100 ). The second row is the name of each student, which is given in the order from left to right and separated by spaces. Each name must contain no more than three English letters or question marks. At least one student's name is not a question mark. The next row is the number of queries (1 <= q <= 100 ). Each group of data contains an integer p (1 <= P <= N), that is, the location of the student to be called (the first one on the left is location 1 ).

Output

The name of each query is output. Note: "middle of X and Y" only when the callee has two recent known students X and Y, and X is on the left of Y.

Sample Input
10A ? ? D ? ? ? H ? ?438610
Sample output
left of DHmiddle of D and Hright of right of H

Hint

A water question; simulate it directly, make judgments based on the location, output the inquiry, and search for the two sides; cannot find '? '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]);//直接就是询问的位置        else        {            while(1)            {                if(left-1>0)                    left=left-1;                if(right+1<=n)                    right=right+1;                if(name[left][0]!='?' && name[right][0]!='?')//在两个中间的情况                {                    printf("middle of %s and %s\n",name[left],name[right]);                    break;                }                 if(name[left][0]=='?' && name[right][0]!='?')//在左边的情况                {                     for(i=1;i<=right-p;i++)//这里还要进行判断一下,可能会在左边的左边                        printf("left of ");                        printf("%s\n",name[right]);                      break;                }                if(name[left][0]!='?' && name[right][0]=='?')//在右边的情况                {                     for(i=1;i<=p-left;i++)                        printf("right of ");                        printf("%s\n",name[left]);                      break;                }            }        }    }    return 0;}



Good Teacher (Computing Program Design Competition for the ninth Hunan University Student)

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.