{ "type": "code_options", "author": "csdn.net", "source": "solution.md", "exercise_id": "5a97ea92895d4fdda13359eeae09f284", "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", "title": "任意多行字符串拆分数值求和", "desc": [ { "content": "\n
编写程序,统计每行字符串中若干整数的和。每行字符串中整数间的分隔符可能有逗号“,”、分号“ ;”和空格,有多少行就求多少行。\n输入格式:\n任意输入若干行由整数构成的字符串(回车换行),整数间以逗号或空格或分号分隔。测试数确保至少有一行数据,字符串中的整数数据均合法有效。最后以一个回车结束输入。\n输出格式:\n对应输出原输入串(一行中的字符序列),冒号后输出各个整数之和。\n
输入样例:
\n\n1; 2 ,3\n2 3; 4\n10,20 30; 40\n9
\n输出样例:
\n\n1; 2 ,3:6\n2 3; 4:9\n10,20 30; 40:100
",
"language": "markdown"
}
],
"answer": [
{
"content": "",
"language": "python"
}
],
"prepared": [
[
{
"content": "",
"language": "python"
}
],
[
{
"content": "",
"language": "python"
}
],
[
{
"content": "",
"language": "python"
}
]
],
"template": {
"content": "stopword = '' \ns = ''\nprint('请输入内容,输入空行回车结束输入:')\nfor line in iter(input, stopword):\n\ts = s + line + \"\\n\"\nprint(s)\nl = s.splitlines()\nfor num in range(0, len(l)):\n\tone = l[num].replace(',', ' ').replace(';', ' ').split()\n\tonesum = 0\n\tfor i in range(0, len(one)):\n\t\tonesum = onesum + int(one[i])\n\tprint(l[num] + \":\" + str(onesum))",
"language": "python"
},
"node_id": "dailycode-45221df1b0024a78bfef72b49e99492c",
"license": "csdn.net",
"created_at": 1637894161,
"topic_link": "https://bbs.csdn.net/topics/600470501"
}