湖南第九届省赛 好老师

I want to be a good teacher, so at least I need to remember all the student names. However, there are

too many students, so I failed. It is a shame, so I don’t want my students to know this. Whenever I

need to call someone, I call his CLOSEST student instead. For example, there are 10 students:

A ? ? D ? ? ? H ? ?

Then, to call each student, I use this table:

Pos Reference

1 A

2 right of A

3 left of D

4 D

5 right of D

6 middle of D and H

7 left of H

8 H

9 right of H

10 right of right of H

Input

There is only one test case. The first line contains n, the number of students (1 ≤ n ≤ 100). The next

line contains n space-separated names. Each name is either ‘?’ or a string of no more than 3 English

letters. There will be at least one name not equal to ‘?’. The next line contains q, the number of

queries (1 ≤ q ≤ 100). Then each of the next q lines contains the position p (1 ≤ p ≤ n) of a student

(counting from left).

Output

Print q lines, each for a student. Note that ‘middle of X and Y ’ is only used when X and Y are

both closest of the student, and X is always to his left.

Sample Input

10

A ? ? D ? ? ? H ? ?

4

3

8

6

10

Sample Output

left of D

H

middle of D and H

right of right of H

模拟一下,就可以了!

就是看right of或者left of的时候要注意,另一边没有人才行,否则就是middle of了

#include<cstdio>
#include<iostream>
using namespace std;
#include<cstring>
char a[105][4];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int m;
    cin>>m;
    while(m--){
        int s;
        cin>>s;
        int i=s-1;
        if(strcmp(a[i],"?")){
            cout<<a[i]<<endl;
        }
        else if(i-1>=0&&strcmp(a[i-1],"?")){
            if(i+1<n&&strcmp(a[i+1],"?"))
                cout<<"middle of "<<a[i-1]<<" and "<<a[i+1]<<endl;
            else
                cout<<"right of "<<a[i-1]<<endl;
        }else if(i+1<n&&strcmp(a[i+1],"?")){
            if(i-1>=0&&strcmp(a[i-1],"?"))
                cout<<"middle of "<<a[i-1]<<" and "<<a[i+1]<<endl;
            else
                cout<<"left of "<<a[i+1]<<endl;
        }else {
            for(int j=2;;++j){
                if(i+j<n&&i-j>=0&&strcmp(a[i+j],"?")&&strcmp(a[i-j],"?")){
                    cout<<"middle of "<<a[i-j]<<" and "<<a[i+j]<<endl;break;
                }else if(i+j<n&&strcmp(a[i+j],"?")){
                    for(int k=0;k<j;++k){
                        cout<<"left of ";
                    }
                    cout<<a[i+j]<<endl;break;
                }else if(i-j>=0&&strcmp(a[i-j],"?")){
                    for(int k=0;k<j;++k){
                        cout<<"right of ";
                    }
                    cout<<a[i-j]<<endl;break;
                }
            }
        }
    }
//  while(1);
    return 0;
}
时间: 2024-08-14 10:47:11

湖南第九届省赛 好老师的相关文章

湖南第九届省赛 高桥和低桥

Q: There are one high bridge and one low bridge across the river. The river has flooded twice, why the high bridge is flooded twice but the low bridge is flooded only once? A: Because the lower bridge is so low that it's still under water after the f

Interesting Calculator 湖南第九届省赛

There is an interesting calculator. It has 3 rows of button. ? Row 1: button 0, 1, 2, 3, - , 9. Pressing each button appends that digit to the end of the display. ? Row 2: button +0, +1, +2, +3, - , +9. Pressing each button adds that digit to the dis

第九届省赛-表达式求值(模拟)

表达式求值 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表达式,则 X+Y, X*Y 也是表达式; *优先级高于+. 3. 如果 X 和 Y 是 表达式,则 函数 Smax(X,Y)也是表达式,其值为:先分别求出 X ,Y 值的各位数字之和,再从中选最大数. 4.如果 X 是 表达式,则 (X)也是表达式. 例如: 表达式 12*(2+3)+Smax(333,220+2

nyoj1273 河南省第九届省赛_&quot;宣传墙&quot;、状压DP+矩阵幂加速

宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做一系列的宣传.为了统一规划,CBA 镇长要求每个宣传栏只能占相邻的两个方格 位置.但这条道路被另一条道路分割成左右两段.CBA 镇长想知道,若每个位置都贴上宣传栏, 左右两段各有有多少种不同的张贴方案. 例如: N=6,M=3, K=2, 左,右边各有 5 种不同的张贴方案 输入 第一行: T 表示

ACM--1334 好老师--湖南省第九届省赛--水

1334: 好老师 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 267  Solved: 131 [Submit][Status][Web Board] Description 我想当一个好老师,所以我决定记住所有学生的名字.可是不久以后我就放弃了,因为学生太多了,根本记不住.但是我不能让我的学生发现这一点,否则会很没面子.所以每次要叫学生的名字时,我会引用离他最近的,我认得的学生.比如有10个学生: A ? ? D ? ? ? H ? ? 想

UVA 12663 第九届省赛 高桥与低桥 树状数组

1 #include <cstdio> 2 #include <math.h> 3 #include <iostream> 4 #include <cstring> 5 #include <cstdlib> 6 #include <algorithm> 7 using namespace std; 8 9 const int maxn = 1e5+10; 10 int c[maxn], a[maxn]; 11 int lowbit(i

ZOJ 3601 Unrequited Love 浙江省第九届省赛

Unrequited Love Time Limit: 16 Seconds      Memory Limit: 131072 KB There are n single boys and m single girls. Each of them may love none, one or several of other people unrequitedly and one-sidedly. For the coming q days, each night some of them wi

机械设备--第九届省赛--深搜

Alpha 公司设计出一种节能的机器设备.它的内部结构是由 N 个齿轮组成.整个机器设备有 一个驱动齿轮,当启动它时,它立即按 10,000 圈/小时转速顺时针转动,然后它又带动与它相切 的齿轮反方向,即逆时针转动.齿轮之间互相作用,每个齿轮都可能驱动着多个齿轮,最终带动 一个工作齿轮完成相应的任务. 在这套设备中,记录了每个齿轮的圆心坐标和齿轮半径.已知驱动齿轮位于(0,0),最终的 工作齿轮位于(Xt, Yt). Alpha 公司想知道传动序列中所有齿轮的转速.所谓传动序列,即能量由驱动齿轮

NYOJ--1276--机器设备(河南省第九届省赛,简单的bfs)

机器设备 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Alpha 公司设计出一种节能的机器设备.它的内部结构是由 N 个齿轮组成.整个机器设备有 一个驱动齿轮,当启动它时,它立即按 10,000 圈/小时转速顺时针转动,然后它又带动与它相切 的齿轮反方向,即逆时针转动.齿轮之间互相作用,每个齿轮都可能驱动着多个齿轮,最终带动 一个工作齿轮完成相应的任务. 在这套设备中,记录了每个齿轮的圆心坐标和齿轮半径.已知驱动齿轮位于(0,0),最终的 工作齿轮位于(Xt,