uva 10602 - Editor Nottoobad

点击打开链接uva 10602


题目意思: 有n个单词需要输入,第一个单词必须要动手输入。现在有两种命令,“repeat the last word”复制最后一个单词,“delete the last symbol”删除最后一个单词的最后一个字母。问我们最少需要动手输入几次


解题思路: 1:思路:排序+枚举每个单词
2:由于有了两种命令,copy最后一个单词和删除最后一个单词的最后一个字母,并且可以无限的使用,所以只要对这些单词排序,然后判断当前单词和上一个单词的关系即可


代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <set>
using namespace std;
#define MAXN 110

int t , n , ans;
string str[MAXN];

void solve() {
    int i , j , k;
    sort(str , str+n);//排序
    ans = str[0].size();
    for(i = 1 ; i < n ; i++){//枚举
        if(str[i][0] != str[i-1][0]){
            ans += str[i].size();
            continue;
        }
        for(j = 0 , k = 0 ; j < str[i-1].size() ; j++ , k++){
            if(str[i-1][j] != str[i][k])
                break;
        }
        ans += str[i].size()-k;
    }
    printf("%d\n" , ans);
    for(i = 0 ; i < n ; i++)
        cout<<str[i]<<endl;
}

int main() {
    //freopen("input.txt" , "r" , stdin);
    scanf("%d" , &t);
    while(t--){
        scanf("%d" , &n);
        for(int i = 0 ; i < n ; i++)
            cin>>str[i];
        solve();
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值