2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal(示例代码
Posted destr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal(示例代码相关的知识,希望对你有一定的参考价值。
题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669
时间限制:1s
空间限制:64MB
题目大意:给定一个长度为2n,由n个大写字母和n小写字母组成的字符串,将对应的字母两两连接,且不相交,按顺序输出没个大写字母对应的小写字母的位置,如果不存在则输出"Impossible"
样例:
/home/destr/Desktop/深度截图_选择区域_20181006175058.png
/home/destr/Desktop/深度截图_选择区域_20181006175126.png
解法:
手动建立结构体,维护一个栈
代码:
#include<bits/stdc++.h>
using namespace std;
struct node{
char v;
int id;
}st[11000];
int main()
{
int n;
char s[11000];
int ans[11000]={0};
int sum1=0,sum2=0;
int top=0;
int tot=0;
cin>>n;
for(int i=1;i<=n*2;i++)
{
cin>>s[i];
if(isupper(s[i]))
{
sum1++;
if(s[i]+32==st[top].v)
{
ans[sum1]=st[top].id;
top--;
}
else
{
top++;
st[top].id=sum1;
st[top].v=s[i];
}
}
else
{
sum2++;
if(s[i]-32==st[top].v)
{
ans[st[top].id]=sum2;
top--;
}
else
{
top++;
st[top].v=s[i];
st[top].id=sum2;
}
}
}
if(top!=0)cout<<"Impossible"<<endl;
else
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
return 0;
}
以上是关于2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal(示例代码的主要内容,如果未能解决你的问题,请参考以下文章
2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest B - Bring Your Own Bombs 离散化+扫描线+计算期望
2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (7/10)
2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest
GYM1014092010-2011 ACM-ICPC, NEERC, Western Subregional Contest
2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)
2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)题解+补题