码迷,mamicode.com
首页 > 其他好文 > 详细

湖南第九届省赛 好老师

时间:2016-05-13 01:05:11      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

湖南第九届省赛 好老师

标签:

原文地址:http://blog.csdn.net/mymilkbottles/article/details/51345341

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!