题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510

时间限制:1s

空间限制:512MB

题目大意:

给定一个字符串,使用%[...]形式将字符串中出现的字符整理到最短和最小(ASCII范围为32~126),可使用的字符有 '-' '^'

题目解法:模拟整理正的和使用 '^' 取反的两个字符串,输出较短较小的那个(注意当所有字符都存在时,输出%[^!]最小)

样例:

代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pi acos(-1.0)
#define mem0(a) memset(a,0,sizeof(a))
#define memf(b) memset(b,false,sizeof(b))
#define ll long long
#define eps 1e-10
#define inf 1e17
#define maxn 101010
int main()
{
string str;
bool a[200];
int b[200];
//mem0(str);'
mem0(b);
int tot=0;
for(int i=32;i<=126;i++)
{
char z=(char)i;
if(z==' '||z>='0'&&z<='9'||z>='A'&&z<='Z'||z>='a'&&z<='z')
b[tot++]=i;
}
memf(a);
getline(cin,str);
//cout<<str;
int num=0,num1=0,num2=0,num3=0;
for(int i=0;i<str.size();i++)
{
a[(int)str[i]]=true;
// if(str[i]==' ')num=1;
// if(str[i]>='0'&&str[i]<='9')num1++;
// if(str[i]>='A'&&str[i]<='Z')num2++;
// if(str[i]>='a'&&str[i]<='z')num3++;
}
// for(int i=32;i<=126;i++)
// {
// printf("%c ",i);
// cout<<a[i]<<" ";
// }
int flag=0;
for(int i=0;i<tot;i++)
{
if(a[b[i]]==false)
{
flag=1;
break;
}
}
if(!flag)
{
cout<<"%[^!]"<<endl;
return 0;
}
string ans1="";
for(int i=0;i<tot;i++)
{
int t=i;
while(a[b[t]])
{
t++;
}
if(t-i>=3)
{
ans1+=(char)(b[i]);
ans1+="-";
ans1+=(char)(b[t-1]);
i=t-1;
}
else if(t-i==2)
{
ans1+=(char)(b[i]);
ans1+=(char)(b[i+1]);
i++;
}
else if(t-i==1)
ans1+=(char)b[i];
}
for(int i=0;i<ans1.size();i++)
{
if(ans1[i]=='a'&&ans1[i+1]=='-')
{
ans1[i]='[';
}
if(ans1[i]=='A'&&ans1[i+1]=='-')
{
ans1[i]=':';
}
if(ans1[i]=='0'&&ans1[i+1]=='-')
{
ans1[i]='!';
}
}
// for(int i=0;i<tot;i++)
// cout<<b[i]<<" ";
string ans2="^";
for(int i=0;i<tot;i++)
{
int t=i;
while(a[b[t]]==false&&t<tot)
{
t++;
}
if(t-i>=3)
{
ans2+=(char)(b[i]);
ans2+="-";
ans2+=(char)(b[t-1]);
i=t-1;
}
else if(t-i==2)
{
ans2+=(char)(b[i]);
ans2+=(char)(b[i+1]);
i++;
}
else if(t-i==1)
ans2+=(char)b[i];
}
for(int i=0;i<ans2.size();i++)
{
if(ans2[i]=='a'&&ans2[i+1]=='-')
{
ans2[i]='[';
}
if(ans2[i]=='A'&&ans2[i+1]=='-')
{
ans2[i]=':';
}
if(ans2[i]=='0'&&ans2[i+1]=='-')
{
ans2[i]='!';
}
}
if(ans1.length()==ans2.length())
{
if(ans1<ans2)
{
cout<<"%["<<ans1<<"]"<<endl;
}
else
cout<<"%["<<ans2<<"]"<<endl;
}
else
{
if(ans1.length()<ans2.length())
cout<<"%["<<ans1<<"]"<<endl;
else cout<<"%["<<ans2<<"]"<<endl;
}
return 0;
}

2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem F. Format的更多相关文章

  1. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem F. Judging Time Prediction 优先队列

    Problem F. Judging Time Prediction 题目连接: http://www.codeforces.com/gym/100253 Description It is not ...

  2. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  3. 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem I. Integral Polygons

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个凸多边形,有一种连接两个 ...

  4. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题

    Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  6. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  7. 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D Problem D. Distribution in Metagonia Input ...

  8. 模拟赛小结:2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest 2019年10月11日 15:35-20:35(Solved 8,Penalty 675 ...

  9. 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest (9/12)

    $$2015-2016\ ACM-ICPC,\ NEERC,\ Northern\ Subregional\ Contest$$ \(A.Alex\ Origami\ Squares\) 签到 //# ...

随机推荐

  1. 使用抓包工具pproxy

    下载地址:https://github.com/hidu/pproxy 一.下载后解压 二.打开pproxy.exe 三.手机连接wifi,设置wifi,代理改为手动,输入代理主机ip,代理主机端口. ...

  2. Hadoop源码学习笔记之NameNode启动场景流程四:rpc server初始化及启动

    老规矩,还是分三步走,分别为源码调用分析.伪代码核心梳理.调用关系图解. 一.源码调用分析 根据上篇的梳理,直接从initialize()方法着手.源码如下,部分代码的功能以及说明,已经在注释阐述了. ...

  3. HIve常用CLI命令

    1. 清楚屏幕:Ctrl+L 或者!Clear 最后加上分号 2. 查看数据仓库中的表:show tables; 3. 查看数据仓库中内置函数:show functions: 4. 查看表结构 :de ...

  4. 树莓3B+_中文支持安装输入法

    参考: https://www.cnblogs.com/collisionzhang/p/7413349.html 莓派默认是采用英文字库的,而且系统里没有预装中文字库,所以即使你在locale中改成 ...

  5. kubernetes常用基础命令

    创建资源对象 创建名为nginx-deploy的控制器资源对象 [root@master ~]# kubectl run nginx-deploy --image=nginx:1.12 --repli ...

  6. 【原创】frozenset集合函数入门及实例

    函数作用 frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素.与之对应的是set函数,set无序排序且不重复,是可变的,有add(),remove()等方法. 函数原型 f ...

  7. Leecode刷题之旅-C语言/python-326 3的幂

    /* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...

  8. 【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

    问题描述 RedisDump 是一个用于 Redis 数据导人/导出的工具,是基于 Ruby 实现的,需要先安装 Ruby.但因为 Mac 自带有 Ruby 所以我直接用gem install red ...

  9. SQL 列转行 分组去重并合并多条记录

    继上篇<SQL 列转行 合并多条记录>后,有网友反馈新的需求还是不太会用. 现举例说明 一,网友需要如下的效果: 其实,这个需求依然可以我上篇的方法进行解答,但为了实现分组,需要disti ...

  10. 对Prolog的感想和我写的一些教程

    我第一次见到Prolog这门独特的编程语言是在<七周七语言(Seven Languages in Seven Weeks)>中看到的.<七周七语言>名字看起来与市面上什么< ...