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. php这是一个随机打印输出字符串的例子

    <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); define(& ...

  2. c# 关键字delegate、event(委托与事件)[MSDN原文摘录][1]

    A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. ...

  3. 【html】【6】div浮动float

    我想 当看完上面的必看链接,拥有一定的基础后也得7天左右, 记住 一定要看完,知道它都有什么,没学会不要紧,哪怕只是有个简单的概念也行, 随着后续的使用慢慢深入学习,现在开始div布局. 必看参考: ...

  4. C winpcap 网络抓包 并获取IP TCP 协议的相关信息

    以太网协议分析函数: void ethernet_protocol_packet_handle (u_char *argument, const struct pcap_pkthdr *packet_ ...

  5. HTML 表单常用的代码元素

    表单: 将数据通过浏览器提交到服务器的媒介.<form action="" method="get/post" ></form> get ...

  6. Echarts地图使用经验-地图变形和添加数据

    关于echart2,echart3地图的使用一点人生经验: 1.echart3,echart2加载地图变形修复. 最近在使用echart2使用过程中,发现加载海南地图会产生变形.如下图,海南地图产生了 ...

  7. Sql更新

    //要传一个DataSet,和若干个表 /// <summary> /// 更新数据库 /// </summary> /// <param name="data ...

  8. CC攻击原理及防范方法和如何防范CC攻击

    一. CC攻击的原理: CC攻击的原理就是攻击者控制某些主机不停地发大量数据包给对方服务器造成服务器资源耗尽,一直到宕机崩溃.CC主要是用来消耗服务器资源的,每个人都有这样的体验:当一个网页访问的人数 ...

  9. matplotlib.transforms

    来自:龙哥盟飞龙 变换教程 像任何图形包一样,matplotlib建立在变换框架之上,以便在坐标系,用户数据坐标系,轴域者坐标系,图形坐标系和显示坐标系之间轻易变换.在95%的绘图中,你不需要考虑这一 ...

  10. leetcode989

    class Solution: def addToArrayForm(self, A, K): i = len(A) - 1 while i >= 0 and K > 0: A[i] += ...