Problem G

Good Teacher

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

Output for the Sample Input

left of D
H
middle of D and H
right of right of H

The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan

  打好基础,顺序查找,没有什么高端算法,就是希望在某些情况下少用各种break ,多用函数return ,这样好一点,少犯些错误。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
int N ;
string str[] ;
void gao(int id){
if(str[id]!="?"){
cout<<str[id]<<endl ;
return ;
}
int L ,R ;
L=R= ;
int left=id- ;
int right=id+ ;
str[]=str[N+]="?" ;
while(left>=&&str[left]=="?"){
R++ ;
left-- ;
}
while(right<=N&&str[right]=="?"){
L++ ;
right++ ;
}
if(L==R&&str[left]!="?"&&str[right]!="?"){
printf("middle of %s and %s\n",str[left].c_str(),str[right].c_str()) ;
return ;
}
if((str[left]!="?"&&str[right]!="?"&&L>R)||str[right]=="?"){
for(int i=;i<=R;i++)
printf("right of ") ;
cout<<str[left]<<endl ;
return ;
}
if((str[left]!="?"&&str[right]!="?"&&L<R)||str[left]=="?"){
for(int i=;i<=L;i++)
printf("left of ") ;
cout<<str[right]<<endl ;
return ;
}
}
int main(){
int M ,id ;
cin>>N ;
for(int i=;i<=N;i++)
cin>>str[i] ;
cin>>M ;
while(M--){
cin>>id ;
gao(id) ;
}
return ;
}

The Ninth Hunan Collegiate Programming Contest (2013) Problem G的更多相关文章

  1. The Ninth Hunan Collegiate Programming Contest (2013) Problem A

    Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...

  2. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem I

    Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

  8. 2018 Arab Collegiate Programming Contest (ACPC 2018) G. Greatest Chicken Dish (线段树+GCD)

    题目链接:https://codeforces.com/gym/101991/problem/G 题意:给出 n 个数,q 次询问区间[ li,ri ]之间有多少个 GCD = di 的连续子区间. ...

  9. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

随机推荐

  1. 转: ExtJS中xtype一览

    转: ExtJS中xtype一览 基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cycl ...

  2. C#利用Windows API 实现关机、注销、重启等操作

    using System; using System.Text; using System.Diagnostics; using System.Runtime.InteropServices; nam ...

  3. hibernate 大对象映射

    1. 在pojo类中 用Blob类和Clob public class Student { private int id; private String name; private int age; ...

  4. angular2 的依赖注入

    angular2 的依赖注入包含了太多的内容,其中的一个重点就是注入器,而注入器又非常难理解,今天我们不深入介绍注入器的内容,可以参考官方文档,我们今天来说注入器的层级. 也就是组件获取服务的容器会选 ...

  5. DBA_Oracle Audit基本概念(概念)

    2014-08-15 Created By BaoXinjian

  6. OAF_架构MVC系列2 - Model的概述(概念)

    2014-06-22 Created By BaoXinjian

  7. 2016 Multi-University Training Contest 4 Bubble Sort(树状数组模板)

    Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s ...

  8. curl 同时发送多个请求

    // 创建一对cURL资源 $ch1 = curl_init(); $ch2 = curl_init(); // 设置URL和相应的选项 curl_setopt($ch1, CURLOPT_URL, ...

  9. Linux命令(14)文件和文件夹权限管理:chmod

    linux文件和文件夹权限简介: chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限. Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方 ...

  10. [实变函数]5.4 一般可测函数的 Lebesgue 积分

    1定义 (1)$f$ 在 $E$ 上积分确定 $\lra$ $\dps{\int_Ef^+(x)\rd x<+\infty}$ 或 $\dps{\int_Ef^-(x)\rd x<+\in ...