CSU - 1334 -好老师(STL-map用法)
https://cn.vjudge.net/contest/157163#problem/E
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long ll;
const int maxn=1100;
const int INF=0x3f3f3f3f;
int t,n,m;
int main()
{
int i;
scanf("%d",&t);
string a;
map<int,string>s;
for(int i=1; i<=t; i++)
{
cin>>a;
s[i]=a;
}
scanf("%d",&n);
for(i=1; i<=n; i++)
{
int j,v;
int l=INF,r=INF;
scanf("%d",&m);
if(s[m]!="?")
cout<<s[m]<<endl;
else if(s[m]=="?")
{
for(j=m-1; j>=1; j--)
{
if(s[j]!="?")
{
l=m-j;
break;
}
}
for(v=m+1; v<=t; v++)
{
if(s[v]!="?")
{
r=v-m;
break;
}
}
if(l==r)
cout<<"middle of "<<s[j]<< " and "<<s[v]<<endl;
else if(l>r)
{
for(int k=1; k<=r; k++)
printf("left of ");
cout<<s[v]<<endl;
}
else
{
for(int k=1; k<=l; k++)
printf("right of ");
cout<<s[j]<<endl;
}
}
}
return 0;
}
//int main()
//{
// int t;
// char str[maxn][4];
// int n,m,i,left,right,num;
// scanf("%d",&t);
// for(i=0; i<t; i++)
// scanf("%s",str[i]);
// scanf("%d",&n);
// while(n--)
// {
// scanf("%d",&m);
// m--;
// if(str[m][0]!='?')
// printf("%s\n",str[m]);
// else
// {
// left=m;
// right=m;
// while(str[left][0]=='?'&&str[right][0]=='?')
// {
// if(left>0)
// left--;
// if(right<t-1)
// right++;
// }
//
// if(str[left][0]!='?'&&str[right][0]!='?')
// printf("middle of %s and %s\n",str[left],str[right]);
// else if(str[left][0]!='?')
// {
// num=m-left;
// for(i=0; i<num; i++)
// printf("right of ");
// printf("%s\n",str[left]);
// }
// else
// {
// num=right-m;
// for(i=0; i<num; i++)
// printf("left of ");
// printf("%s\n",str[right]);
// }
// }
// }
// return 0;
//}
CSU - 1334 -好老师(STL-map用法)的更多相关文章
- c++ STL map 用法
map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...
- STL map 用法
首先make_pair Pairs C++标准程序库中凡是"必须返回两个值"的函数, 也都会利用pair对象 class pair可以将两个值视为一个单元.容器类别map和mul ...
- STL map用法总结(multimap)
2017-08-19 10:58:52 writer;pprp #include <map> #include <string> #include <iostream&g ...
- STL:map用法总结
一:介绍 map是STL的关联式容器,以key-value的形式存储,以红黑树(平衡二叉查找树)作为底层数据结构,对数据有自动排序的功能.命名空间为std,所属头文件<map> 二:常用操 ...
- POJ2503 STL map用法
2017-08-21 15:42:01 writer:pprp 除了用到map以外,输入也是一个问题 用到了sscanf详情请看上一篇博客 /* theme:第一章 - 分治算法 name: POJ ...
- C++中的STL中map用法详解(转)
原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解 Map是STL的一个关联容器,它提供 ...
- csuoj 1334: 好老师
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1334 1334: 好老师 Time Limit: 1 Sec Memory Limit: 128 ...
- std::map用法
STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用. 在STL模板类中,用于线性数据存储管理的类主要有vector, list, map 等等.本文主要 ...
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- ES6中Set 和 Map用法
JS中Set与Map用法 一.Set 1.基本用法 ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. ...
随机推荐
- 【NOIP】提高组2012 借教室
[算法]线段树||二分+前缀和 [题解]线段树记录区间加值和区间最大值. #include<cstdio> #include<algorithm> using namespac ...
- 如何设计一个优雅健壮的Android WebView?(下)
转:如何设计一个优雅健壮的Android WebView?(下) 前言 在上文<如何设计一个优雅健壮的Android WebView?(上)>中,笔者分析了国内WebView的现状,以及在 ...
- floyd骚操作——传递闭包
传递闭包的含义指通过传递性推导出尽量多的元素之间的关系,而传递闭包一般都是采用floyd算法. 下面用两道题来实现传递闭包: Problem 1(POJ3660): 题目链接:http://poj.o ...
- Anniversary party(树上dp+HDU1520)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目: 题意:一个学校要办校庆,校长决定邀请员工参加,但是下属和他的直系同时参加的话,下属将会无 ...
- 【HNOI】 c tree-dp
[题目描述]给定一个n个节点的树,每个节点有两个属性值a[i],b[i],我们可以在树中选取一个连通块G,这个连通块的值为(Σa[x])(Σb[x]) x∈G,求所有连通块的值的和,输出答案对1000 ...
- base--AuditObject
//参考base-4.0.2.jarpublic class AuditObject extends HashMap<String, Object> implements TimeRefe ...
- scikit-learn中的岭回归(Ridge Regression)与Lasso回归
一.岭回归模型 岭回归其实就是在普通最小二乘法回归(ordinary least squares regression)的基础上,加入了正则化参数λ. 二.如何调用 class sklearn.lin ...
- 【nginx】nginx的安装及测试
nginx中文文档:http://www.nginx.cn/doc/index.html 1.到官网下载nginx的压缩包: https://nginx.org/ 2.解压到相应的目录,比如我是e ...
- [Leetcode Week16]Insertion Sort List
Insertion Sort List 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/insertion-sort-list/description/ ...
- Kotlin 学习使用之旅(二)
为什么从二开始呢?再此之前已经有了一篇了,那是刚知道kotlin的时候草(chao)来(chao)的并且学习一篇, 这次是自己在项目中正式使用并且遇到的一些问题记录,供kotlin新入门的童鞋参考,避 ...