首页 > 代码库 > bzoj4839 [Neerc2016]Abbreviation

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;
}
View Code

 

bzoj4839 [Neerc2016]Abbreviation