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. IRedisClient 常用方法说明

    事实上,IRedisClient里面的很多方法,其实就是Redis的命令名.只要对Redis的命令熟悉一点就能够非常快速地理解和掌握这些方法,趁着现在对Redis不是特别了解,我也对着命令来了解一下这 ...

  2. 获取网页URL地址及参数等的两种方法(js和C#)

    转:获取网页URL地址及参数等的两种方法(js和C#) 一 js 先看一个示例 用javascript获取url网址信息 <script type="text/javascript&q ...

  3. metaspolit教程

    网上的安装方式都是抄来抄去,我也抄了下,不过好歹自己试了下,有所不同 git clone https://github.com/rapid7/metasploit-framework.git vim ...

  4. 【gradle】之maven主库找不到Could not find org.restlet.jee:org.restlet:2.1.1

    Could not find org.restlet.jee:org.restlet:2.1.1. 我是用gradle构建solr的时候出现的这个错误,通过google查询到这么一段解释 For th ...

  5. MyEclipse 设置注释

    MyEclipse设置注释的方法 windows-Preferences-(弹出窗口) 单击[Edit]后弹出编辑窗口,然后进行编辑

  6. 黄聪:wordpress如何扩展TinyMCE编辑器,添加自定义按钮及功能

    在functions.php文件里面添加: add_action( 'admin_init', 'my_tinymce_button' ); function my_tinymce_button() ...

  7. PLSQL_基础系列02_分组函数GROUP BY / ROLLUP / CUBE(案例)

    2014-11-30 Created By BaoXinjian

  8. BIP_开发案例09_结合JavaCP通过BIP API输出报表dataprocess / rtfprocess / foprocess(案例)

    20150814 Created By BaoXinjian

  9. Python 图形 GUI 库 pyqtgraph

    原文  Python 图形 GUI 库 pyqtgraph pyqtgraph 是纯 Python 图形 GUI 库,基于PyQT4 /pyside和NumPy.它主要目的用于在数学/科学/工程中.M ...

  10. phpmyadmin数据库导入出错

    SQL 查询: -- phpMyAdmin SQL Dump-- version 3.5.1-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: ...