ReCkLeSs ToMmY 2018-11-05 09:45 采纳率: 0%
浏览 910

acm oj报错runtime error SIGSEGV(没有用数组,没有除以0),求大神解答

问题: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;

}

  • 写回答

1条回答 默认 最新

  • devmiao 2018-11-05 15:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了