#include <string>
#include <algorithm>
#include <iostream>
int main()
{
string str;
string str1;
int h = 0;
cin >> str;
if (str.length() > 10)
{
str1 += str.front();
h = str.length() - 2;
string s = to_string(h);
str1 += s;
str1 += str.back();
cout << str1;
}
else cout << str;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译在XCode中,但不在codeforces.ru/上
?an't compile program.cpp:
program.cpp: In function 'int main()':
program.cpp:23:21: error: 'std::string' has no member named 'front'
program.cpp:27:29: error: 'to_string' was not declared in this scope
program.cpp:32:21: error: 'std::string' has no member named 'back'
Run Code Online (Sandbox Code Playgroud)
string::front在c ++ 11中引入.在mac上确保你使用clang,因为g ++在osx上没有更新,并且使用命令行选项clang++ -std=c++11 your_program.cpp.您可能还需要使用该选项-stdlib=libc++