A - Abbreviation (模拟)

题目链接:https://cn.vjudge.net/problem/Gym-101190A

题目大意:将串中符合首字符大写其余字母小写的单词和其他符合这种情况的只间隔一个空格的单词的首字母提出来,其余字符用括号括起来

思路概括:遍历整个串,将符合要求的单词预处理出来,然后在遍历去提取加括号

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define lt k<<1
#define rt k<<1|1
#define lowbit(x) x&(-x)
#define lson l,mid,lt
#define rson mid+1,r,rt
using namespace std;
typedef long long ll;
typedef long double ld;
//#define int ll
#define ios ios::sync_with_stdio(false);cin.tie(nullptr);
#define mem(a, b) memset(a, b, sizeof(a))
const double pi = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e6 + 50;

bool ju_d(char ch)
{
    if(ch >='A' && ch <= 'Z') return true;
    else return false;
}
bool ju_x(char ch)
{
    if(ch >= 'a' && ch <= 'z') return true;
    else return false;
}
char s[maxn];
char t[maxn];
int vis[maxn];
int main()
{
    freopen("abbreviation.in", "r", stdin);
    freopen("abbreviation.out", "w", stdout);
    while(gets(s))
    {
        mem(vis, 0);
        int len = strlen(s);
        for(int i=0; i<len; i++)
        {
            bool flag = true;
            if(ju_d(s[i]))
            {
                if(i ==0 || s[i - 1] == '.' || s[i-1] == ',' || s[i-1] == ' ')
                {
                    int x = i;
                    while(s[i] != ' ')
                    {
                        i++;
                        if(ju_d(s[i])) flag = false;
                        if(s[i] == '.' || s[i] == ',' || s[i] == '\0')
                        {
                            break;
                        }
                    }
                    if(flag)
                    {
                        vis[x] = 1;
                        vis[i-1] = 1;
                    }
                }
            }
        }
//        for(int i=0; i<len; i++)
//        {
//            cout << i << ' ' << vis[i] << endl;
//        }
        int pos = 0, y = -1, num, cnt;
        for(int i=0; i<len; i++)
        {
            bool flagg = true;
            if(vis[i])
            {
                t[pos++] = s[i];
                for(int j=i+1; j<len; j++)
                {
                    if(s[j] == ' ')
                    {
                        if(!vis[j + 1])
                        {
                            flagg = false;
                            break;
                        }
                        else if(!ju_x(s[j-1]) || !ju_x(s[j+2]))
                        {
                            flagg = false;
                            break;
                        }
                        else if(vis[j-1] && vis[j+1] && ju_x(s[j-1]) && !ju_x(s[j+1]))
                        {
//                            cout << "!!" << endl;
                            vis[j-1] = 0;
                            vis[j+1] = 0;
                            t[pos++] = s[j+1];
                            y = j+1;
                        }
                    }
                    if(s[j] == '.' || s[j] == ',') break;
                }
//                cout << "y" << ' ' << y << endl;
                if(y == -1) pos--;
                if(y!=-1)
                {
//                    cout << flagg << endl;
                    if(y!=-1)
                    {
                        t[pos++] = ' ';
                        t[pos++] = '(';
                    }
//                    cout << "y" << ' ' << y << endl;
                    while(y < len)
                    {
                        vis[y] = 0;
                        if(s[y] == '.' || s[y] == ',' || s[y] == ' ')
                        {
                            break;
                        }
                        y++;
                    }
                }
            }
            t[pos++] = s[i];
            if(i==y-1)
            {
//                cout << i << endl;
                t[pos++] = ')';
                y = -1;
            }
        }
//        for(int i=0; i<len; i++)
//        {
//            cout << i << ' ' << vis[i] << endl;
//        }
        for(int i=0; i<pos; i++) cout << t[i];
        cout << endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<template> <div> <a-table :pagination="false" :columns="columns" :dataSource="dataSource"> <!-- //循环展示数据或input输入框 --> <template v-for="col in ['abbreviation', 'fullName', 'nodes']" :slot="col" slot-scope="text, record, index"> <div :key="col"> <a-input v-if="editableData[record.key]" v-model="editableData[record.key][col]" /> <template v-else>{{ text }}</template> </div> </template> <!-- //操作 --> <template slot="operation" slot-scope="text, record, index"> <span v-if="editableData[record.key]"> <a-icon type="check" @click="save(record.key)" /> </span> <span v-else> <a-icon type="delete" @click="deleteItem(record.key)" /> <a-icon type="edit" @click="edit(record.key)" /> <a-icon type="plus" v-if="index == dataSource.length - 1" @click="addItem(record.key)" /> </span> </template> </a-table> <div @click="Edats">编辑</div> </div> </template> <script> import { cloneDeep } from 'lodash' export default { data() { return { editableData: [], //正在编辑的数组 columns: [ { title: '简称', dataIndex: 'abbreviation', scopedSlots: { customRender: 'abbreviation', }, }, { title: '全称', dataIndex: 'fullName', scopedSlots: { customRender: 'fullName', }, }, { title: '来源', dataIndex: 'nodes', scopedSlots: { customRender: 'nodes', }, }, { title: '操作', dataIndex: 'operation', scopedSlots: { customRender: 'operation' }, }, ], //表格数据 dataSource: [ { key: 0, abbreviation: '简称1', fullName: '全称1', nodes: '来源1', }, { key: 1, abbreviation: '简称2', fullName: '全称2', 实现一键保存
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值