题目来源: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. Node调试

    之前调试node代码简单粗暴,直接在代码打印日志,控制台观察日志,效率低下~ 原来后端node代码也可以通过Chrome断点调试,以下是调试方法. (1)找到node启动的进程 ps aux|grep ...

  2. Call to a member function allowField() on null 错误总结

    Call to a member function allowField() on null 在空对象上调用  allowField() 没有该模型对象无法调用,需要创建相应的模型 错误版本: if ...

  3. Leecode刷题之旅-C语言/python-263丑数

    /* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...

  4. Verilog HDL 使用规范(一)

    本博文参考:<大规模逻辑设计指导书>,对于写出规范的代码,培养良好的代码风格颇有裨益. wire and register 一个reg变量只能在一个always语句中赋值: 这个说明至关重 ...

  5. Freemarker入门(一)——入门与基本概述

    1.概述 1.文档 完美的中文文档:http://freemarker.foofun.cn/ 2.是什么 FreeMarker是一个用Java语言编写的模板引擎.它基于模板来生成文本输出.Freema ...

  6. 20155338 2016-2017-2 《Java程序设计》第10周学习总结

    20155338 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 网络编程 · 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事 ...

  7. virsh常用维护命令

    virsh常用命令 一些常用命令参数 [root@kvm-server ~]# virsh --help                                     #查看命令帮忙 [ro ...

  8. LVS入门篇(二)之LVS基础

    1. LVS介绍 LVS是Linux虚拟服务器(LinuxVirtualServers),使用负载均衡技术将多台服务器组成一个虚拟服务器.它为适应快速增长的网络访问需求提供了一个负载能力易于扩展,而价 ...

  9. EmitMapper自动映射工具

             在实体与DTO之间,我们一般都需要进行映射.如果手动的来进行转换,实在是太麻烦.所以就产生了很多映射工具,比如AutoMapper,EmitMapper.而经过一些对比,EmitMa ...

  10. java IO操作:FileInputStream,FileOutputStream,FileReader,FileWriter实例

    FileInputStream <span style="font-family:Verdana;">import java.io.File; import java. ...