codeforces 刷题d1

本文介绍了一个C语言程序,用于将输入文本中的长词(超过10字符)替换为首尾字母加上中间字符数的缩写,如localization变为l10n。程序要求注意内存限制和正确处理输入输出格式。
摘要由CSDN通过智能技术生成

A. Way Too Long Words

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.

Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.

This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.

Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".

You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

Examples

input

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

output

word
l10n
i18n
p43s

题解

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    char a[101];
    int n;
    scanf("%d",&n);
    int i;
    getchar();
    for(i=0;i<n;i++)
    {
        gets(a);
        if(strlen(a)>10)
        {
            printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]);
        }
        else
        puts(a);
    }
    return 0;
}
输入输出

错误示范

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    char a[81];//题目限制了字符长度是一到一百,应该改为a[101]
    //char a[80];在早期的C语言中,80 字符宽度被广泛用于标准文本终端的宽度。
    //这样的选择可以确保在一行上能够容纳足够的字符,以便在终端上显示文本。
    //但不适用于本道题
    int n;
    scanf("%d",&n);
    //在使用 scanf("%d", &n); 读取整数后
    //缓冲区中还留有一个回车符('\n'),而 gets(a); 会读取这个回车符
    //导致输入提前结束。
    //可以改用 getchar(); 来吸收这个回车符
    int i;
    for(i=0;i<n;i++)
    {
        gets(a);
        if(strlen(a)>10)
        {
            printf("%c%d%c",a[0],strlen(a)-2,a[strlen(a)-1]);//这里忘记加\n
        }
        else
        puts(a);
    }
    return 0;
}
错误的输入输出

总结:

1.注意细节。要用多少内存空间,printf()里面一定要加\n

2.遇到scanf和gets()同时存在时,要根据情况看是否要添加getchar()回收换行符

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zero_019

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值