问题:This problem requires you to format some texts, you need to read the problem description carefully to prevent Presentation Error. Read the Input and Output for more infomation.
Input
The input consists several cases.
For each case, the first line is an integer n(n ≥ 0), without any extra space character; following several lines, each line has several words separated by one or more space characters, note that the space characters may also appear at the beginning or ending of the line. Each case is ended by a line containing exactly "end" with no extra space characters.
There are at most 100 lines for each test case, each line has at most 1000 characters. Processing to the end of file.
Output
There is a number n for each case, for each line of words in this case, you should print all the words in a line separated by exactly n space characters, with no space characters at the beginning or the ending of the output line; but if the line is the end of this case, print exactly "-----" instead.
Sample Input
2
jin tian shi ge hao ri zi
xin xiang de shi er dou neng cheng
ming tian shi ge hao ri zi
da kai le jia men zan ying chun fen
end
1
hao yun lai zhu ni hao yun lai
hao yun dai lai le xi he ai
end
end
3
end dne edn nde
end
end
10
end
Sample Output
jin tian shi ge hao ri zi
xin xiang de shi er dou neng cheng
ming tian shi ge hao ri zi
da kai le jia men zan ying chun fen
hao yun lai zhu ni hao yun lai
hao yun dai lai le xi he ai
end
end dne edn nde
end
代码:
#include iostream
#include stdio.h
#include ctype.h
#include string
#include sstream
using namespace std;
int main()
{ int space,flag=1;
string m;
string word;
scanf("%d", &space);
getchar();
part1:
while (1)
{
getline(cin, m);
string flag;
if (m == "end")
{
printf("-----\n");
goto part1;
}
while (1)
{
flag = m.at(m.length() - 1);
if (flag == " ")
{
m.erase(m.length()-1, 1);
if (m == "")
{
goto part1;
}
}
else
{
break;
}
}
stringstream ss(m);
string text = "";
int mark(0);
while (!ss.eof())
{
ss >> word;
while (word.find(" ") == 0)
{
word = word.erase(0, 1);
}
while (word.find(" ") == word.length())
{
word = word.erase(word.length(), 1);
}
text += word;
for (int i = 1; i <= space; i++)
{
text += " ";
}
}
text.erase(text.length() - space, text.length());
cout << text << "\n";
}
return 0;
}