bzoj4839 [Neerc2016]Abbreviation
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4839
【题解】
pkusc怎么出bzoj原题啊
字符串随便处理一下就行了,大模拟
pkusc:2A(freopen调试没删)
线下:2A(数组不够大)
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + ;
const int mod = 1e9+; # define RG register
# define ST static char str[]; char s[][];
int sn = ;
char t[];
char ans[];
int tn = , n = ; inline bool isok(int i) {
if(!isupper(s[i][])) return ;
int len = strlen(s[i]);
if(len == ) return ;
for (int j=; j<len; ++j)
if(!islower(s[i][j])) return ;
return ;
} inline bool isBlank(int i) {
int len = strlen(s[i]);
if(len != ) return ;
return s[i][] == ' ';
} int main() {
// freopen("bzoj4839.in", "r", stdin);
while(cin.getline(str, )) {
int len = strlen(str);
sn = ;
for (int i=; i<len; ++i) {
if(isupper(str[i]) || islower(str[i])) {
tn = ;
int j = i;
while(isupper(str[j]) || islower(str[j])) {
t[tn++] = str[j];
++j;
}
++sn;
for (int j=; j<tn; ++j)
s[sn][j] = t[j];
s[sn][tn] = ;
i = j-;
} else {
++sn; s[sn][] = str[i];
s[sn][] = ;
}
}
// for (int i=1; i<=sn; ++i) printf("%s==\n", s[i]);
n = ;
for (int i=; i<=sn; ++i) {
if(!isok(i)) {
for (int j=; s[i][j]; ++j)
ans[n++] = s[i][j];
} else {
int j = i;
while(j+ <= sn && isBlank(j+) && isok(j+)) j += ;
if(j == i) {
for (int k=; s[i][k]; ++k)
ans[n++] = s[i][k];
} else {
for (int k=i; k<=j; k+=)
ans[n++] = s[k][];
ans[n++] = ' ';
ans[n++] = '(';
for (int k=i; k<=j; k++)
for (int l=; s[k][l]; ++l)
ans[n++] = s[k][l];
ans[n++] = ')';
i = j;
}
}
}
ans[n] = ;
printf("%s\n", ans);
}
return ;
}
bzoj4839 [Neerc2016]Abbreviation的更多相关文章
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Valid Word Abbreviation 验证单词缩写
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- Leetcode: Minimum Unique Word Abbreviation
A string such as "word" contains the following abbreviations: ["word", "1or ...
- Leetcode: Valid Word Abbreviation
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
- 411. Minimum Unique Word Abbreviation
A string such as "word" contains the following abbreviations: ["word", "1or ...
- Leetcode Unique Word Abbreviation
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- 288. Unique Word Abbreviation
题目: An abbreviation of a word follows the form <first letter><number><last letter> ...
- [Locked] Unique Word Abbreviation
Unique Word Abbreviation An abbreviation of a word follows the form <first letter><number&g ...
随机推荐
- js解决img标签加载失败显示默认图片
问题: 为所有显示楼盘的页面添加一个加载失败的默认图片. 基本思路: img标签中有个onerror属性,专门用来处理加载失败的事件.所以可以用jquery添加onerror属性,在onerror中加 ...
- 【java并发编程实战】第七章:取消与关闭
停止线程的几种方式 一般的逻辑停止 public class ThreadInterruptTest { public static volatile boolean cancel = true; p ...
- spring+apache dbcp +oracle 连接池配置以及优化
特此记录 <!-- 数据源配置, 使用应用中的DBCP数据库连接池 --> <bean id="dataSource" class="org.apach ...
- Jquery append()总结(一) 转载
转载自:http://dushanggaolou.iteye.com/blog/1173457 append(content) /** * 向每个匹配的元素内部追加内容. * 这个操作与对指定的元素 ...
- HDU 5794 A Simple Chess Lucas定理+dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5794 题意概述: 给出一个N*M的网格.网格上有一些点是障碍,不能经过.行走的方式是向右下角跳马步.求 ...
- BZOJ 4011 HNOI2015 落忆枫音 DAG上的dp(实际上重点在于分析)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4011 题意概述:给出一张N点的DAG(从1可以到达所有的点),点1的入度为0.现在加一条原 ...
- await和async再学习
await太不容易理解了,自己常常迷惑,不知道该怎么用. 文章:探索c#之Async.Await剖析 这篇文章,有一个很清晰的描述: 使用Async标记方法Async1为异步方法,用Await标记Ge ...
- Java的同步容器和并发容器
前言: 之前在介绍Java集合的时候说到,java提供的实现类很少是线程安全的.只有几个比较古老的类,比如Vector.Hashtable等是线程安全的,尤其是Hashtable,古老到连命名规范都没 ...
- storm-kafka版本不匹配的问题
storm集群是1.0.0版本,kafka的集群版本是0.10.0,所以想当然的使用了kafka_2.10-0.10.0.1.jar作为storm-kafka-1.0.0.jar的依赖使用, 没想到导 ...
- capacilitys docker中的权限设置 privileged
capacilities是docker 中对docker权限设置的重要方面: http://blog.csdn.net/wangpengqi/article/details/9821227 上面这篇文 ...