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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器