The Ninth Hunan Collegiate Programming Contest (2013) Problem G
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的更多相关文章
- 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 ...
- 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 ...
- 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. ...
- 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: ...
- 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, ...
- 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 ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
- 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 的连续子区间. ...
- German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
随机推荐
- 查看SQL执行计划
一用户进入某界面慢得要死,查看SQL执行计划如下(具体SQL语句就不完全公布了,截断的如下): call count cpu elapsed disk ...
- 【java】 java 集合类UML图
- Sublime发布Markdown博客
Sublime发布Markdown博客 下载Sublime插件 插件 按照上面网页中的说明操作 修改插件包中的文件cnblogs.py 第84行,'author'改为自己的邮箱 第86行,'categ ...
- 设置JSP不做浏览器缓存
CacheFilter代码: package com.my.filter; import java.io.*; import javax.servlet.*; import javax.servlet ...
- 使用 Windows PowerShell 来管理和开发 windowsazure.cn 账户的特别注意事项
6月6日,微软面向中国大陆用户开放了Microsoft Azure公众预览版的申请界面.大家可以申请免费的 beta 试用,收到内附邀请码的通知邮件后只需输入激活码即可开始免费试用.具体网址为: ht ...
- C#生成二维码示例
其实现在二维码越来越流行,网上也有很多生成二维码的类库.写一下WEB生成二维码注意事项吧! 目前C#生成二维码大部分都是使用ThoughtWorks.QRCode或者ZXing类库生成,主要说一下Th ...
- 事件日志ID 2511:服务器服务无法重新创建 <sharename> 共享关系,因为 <address> 目录已不再存在
服务器服务无法重新创建 QQMusicDownload 共享关系,因为 D:\QQMusic\QQMusicDownload 目录已不再存在.请运行 "net share QQMusicDo ...
- 拖拽碰撞--原声js(自身理解上新的方法)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- hive查询语句
一. 为什么hive是数据仓库 hive局限于hdfs, 不能进行记录级别的增删改 hive底层的mapreduce启动耗时很长, 无法做到传统数据库的秒查, 只适合离线分析 hive不支持事务, 无 ...
- import了sun开头的类,虽然它在代码里压根就没派上用处!但是必须得引用!
package action; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io. ...