Getting string Exercises long, long string of explanations

Written for: http://codeforces.com/problemset/problem/71/A

Title Description

Long, long string is a string such as "localization" or "internationalization", these strings contain many words, so much effort, when you transcribe these words.
We define a long string long string, if and only if the length of the string is greater than 10.
We are now in the word simplified, so all good long strings need to be simplified.
Our simplified as follows: s for a string, if it is a good long string (longer than 10), then we convert it to splice three portions: the
first portion is the first letter s;
second portion is the number after the first initial and last letter s remaining elements removed;
third part is the last letter s.
For example, for a string of "localization", its length is 12, more than 10, so it is a good long string. Result of its operation is simplified "l10n".
After the operation of the "internationalization" simplified as "i18n"
result while the "apple" or simplified operation itself - "apple", since the number of elements in the word does not exceed 10.
You are given a number of words, you need to output once after every word simplified.

Input Format

Comprising a first line of input integer \ (n-(. 1 \ n-Le \ Le 100) \) , for indicating the number of words you need treatment.
The next \ (n-\) lines, each line comprising a string s (length of between 1 and 100 s).

Output Format

Output \ (n-\) rows, each row corresponding to the result of the input word simplified.

Sample input

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

Sample Output

word
l10n
i18n
p43s

Topic analysis

For each string \ (S \) , assuming its length is \ (n-\) , if its length \ (\ Le \) 10, is output as we; otherwise, we only need to output \ (s [0] + (n-2) + s [n-1] \) on it.
Using the code char array to achieve the following:

#include <bits/stdc++.h>
using namespace std;

char ch[110];
int n, m;

int main() {
    cin >> n;
    while (n --) {
        cin >> ch; m = strlen(ch);
        if (m <= 10) cout << ch << endl;
        else cout << ch[0] << m - 2 << ch[m-1] << endl;
    }
    return 0;
}

Using the code string to achieve the following:

#include <bits/stdc++.h>
using namespace std;

string s;
int n, m;

int main() {
    cin >> n;
    while (n --) {
        cin >> s; m = s.length();
        if (m <= 10) cout << s << endl;
        else cout << s[0] << m - 2 << s[m-1] << endl;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/zifeiynoip/p/11450560.html