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 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

char str[1010]; 

char s[1010][1010];
int sn = 0;
char t[1010];
char ans[6010];
int tn = 0, n = 0; 

inline bool isok(int i) {
    if(!isupper(s[i][0])) return 0;
    int len = strlen(s[i]);
    if(len == 1) return 0;
    for (int j=1; j<len; ++j)
        if(!islower(s[i][j])) return 0;
    return 1;
}

inline bool isBlank(int i) {
    int len = strlen(s[i]);
    if(len != 1) return 0;
    return s[i][0] == ‘ ‘;
}

int main() {
//    freopen("bzoj4839.in", "r", stdin);
    while(cin.getline(str, 1000)) {
        int len = strlen(str);
        sn = 0;
        for (int i=0; i<len; ++i) {
            if(isupper(str[i]) || islower(str[i])) {
                tn = 0;
                int j = i;
                while(isupper(str[j]) || islower(str[j])) {
                    t[tn++] = str[j];
                    ++j;
                }
                ++sn;
                for (int j=0; j<tn; ++j)
                    s[sn][j] = t[j];
                s[sn][tn] = 0;
                i = j-1;
            } else {
                ++sn; s[sn][0] = str[i];
                s[sn][1] = 0;
            }
        }
//        for (int i=1; i<=sn; ++i) printf("%s==\n", s[i]);
        n = 0;
        for (int i=1; i<=sn; ++i) {
            if(!isok(i)) {
                for (int j=0; s[i][j]; ++j)
                    ans[n++] = s[i][j];
            } else {
                int j = i;
                while(j+2 <= sn && isBlank(j+1) && isok(j+2)) j += 2;
                if(j == i) {
                    for (int k=0; s[i][k]; ++k)
                        ans[n++] = s[i][k];
                } else {
                     for (int k=i; k<=j; k+=2)
                         ans[n++] = s[k][0];
                    ans[n++] = ‘ ‘;
                    ans[n++] = ‘(‘;
                    for (int k=i; k<=j; k++)
                        for (int l=0; s[k][l]; ++l)
                            ans[n++] = s[k][l];
                    ans[n++] = ‘)‘;
                    i = j;
                }
            }
        }
        ans[n] = 0;
        printf("%s\n", ans);
    }
    return 0;
}

时间: 2024-10-31 03:59:23

bzoj4839 [Neerc2016]Abbreviation的相关文章

ZOJ 2947: Abbreviation

Abbreviation ///@author Sycamore, ZJNU; ///@date 8/6/2017 #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { bool same = true; int N, M; cin >> N; s

[LeetCode] Word Abbreviation 单词缩写

Given an array of n distinct non-empty strings, you need to generate minimal possible abbreviations for every word following rules below. Begin with the first character and then the number of characters abbreviated, which followed by the last charact

【模拟】Gym - 101190A - Abbreviation

让你把所有的"连续的仅有首字母大写的"词组用缩写表示,并且在后面用括号注明原词组. #include<cstdio> #include<cstring> using namespace std; char s[130]; bool iszimu(char c){ return ((c>='A' && c<='Z') || (c>='a' && c<='z')); } bool isbig(char c){

Leetcode: Unique Word Abbreviation

An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it --> it (no abbreviation) 1 b) d|o|g --> d1g 1 1 1 1---5----0----5--8 c) i|nternationalizatio|n --&

288. Unique Word Abbreviation

题目: An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it --> it (no abbreviation) 1 b) d|o|g --> d1g 1 1 1 1---5----0----5--8 c) i|nternationalizatio|n

408. Valid Word Abbreviation

Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" contains only the following valid abbreviations: ["word", "1ord", "w1rd", &

411. Minimum Unique Word Abbreviation

A string such as "word" contains the following abbreviations: ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "

Unique Word Abbreviation

An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it --> it (no abbreviation) 1 b) d|o|g --> d1g 1 1 1 1---5----0----5--8 c) i|nternationalizatio|n --&

Valid Word Abbreviation Leetcode

Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" contains only the following valid abbreviations: ["word", "1ord", "w1rd", &