A - Abbreviation (字符串模拟)

A - Abbreviation (模拟)

题目链接:http://codeforces.com/gym/101190/attachments

题意:有一些单词组成的句子,把它们改变一下形式输出。

比如:This is ACM North Eastern European Regional Contest,

改成:This is ACM NEERC (North Eastern European Regional Contest),

思路:字符串的模拟最好用string类,里面一个+号直接加字符很好用。并且在“单词”数量不多的情况下尽量把每个“单词”都提取出来再进行处理。

代码:

#include <bits/stdc++.h>

using namespace std;

string a[202];
string b[202];
string s,sum;
int cnt1,cnt2,cnt;
char first[105];
int i,j,len;

int isok( string a )
{
    if ( a[0]<'A'||a[0]>'Z' ) {
        return 0;
    }
    if ( a.size()<=1 ) {
        return 0;
    }
    for ( int i=1; i<a.size(); i++ ) {
        if ( a[i]<'a'||a[i]>'z' ) {
            return 0;
        }
    }
    return 1;
}

void pri()
{
    if ( cnt<=1 ) {
        cout << sum ;
    }
    else {
        for ( int j=0; j<cnt; j++ ) {
            cout << first[j];
        }
        cout << " (" << sum << ")";
    }
    sum = "";
    cnt = 0;
}

int main()
{
    freopen("abbreviation.in","r",stdin);
    freopen("abbreviation.out","w",stdout);
    while ( getline(cin,s) ) {
        len = s.size();
        cnt1 = cnt2 = 0;
        for ( i=0; i<len; ) {
            a[cnt1] = "";
            while ( isalpha(s[i]) ) {
                a[cnt1]+=s[i];
                i ++;
            }
            cnt1 ++;
            b[cnt2] = "";
            while ( !isalpha(s[i])&&i<len ) {
                b[cnt2] += s[i];
                i ++;
            }
            cnt2 ++;
        }
        sum = "";
        cnt = 0;
        for ( i=0; i<cnt1; i++ ) {
            if ( isok(a[i]) ) {
                if ( sum!="" ) {
                    sum += b[i-1];
                }
                sum += a[i];
                first[cnt++] = a[i][0];
                if ( b[i]!=" " ) {
                    pri();
                    cout << b[i];
                }
            }
            else {
                if ( i>=1 && sum!="" ) {
                    pri();
                    cout << b[i-1];
                }
                else {
                    pri();
                }
                cout << a[i] << b[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、付费专栏及课程。

余额充值