输出格式
Description
张老师是中北大学一位德高望重的老教授,他的学生真可谓是桃李满天下。但随着时间的流逝,他老人家的视力逐渐下降了,阅读起文章来很费劲,尤其是看到一大段文字时经常感到头晕,因此他想让你为他编写一个程序将文章的每一段转化成一句一行的形式,并在每行的前面加上相应的序号,还要在每段的首部都加一排“*”以便他老人家阅读。
Input
有多段文字,每段文章开头都有两个空格,每段文字不会多余10000字符。每段文字至少包含一句。
Output
将每段文章中的每句文字分行输出,并在每句前加上相应的序号。每段文字的首句前加上一排“*”号,使最后一个“*”与每段文字的首句的“.”上下对齐。每一段输出后空一行。(如样例输出 )
Example Input
Do you want to succeed? Stop crazy think about how to make yourself successful.
You will print to standard output either the word ``unsolvable''.
Example Output
*************************
1 Do you want to succeed?
2 Stop crazy think about how to make yourself successful.
*******************************************************************
1 You will print to standard output either the word ``unsolvable''.
Hint
每句话的末尾以“.”“?”“!”结束,有的句尾“.”“?”“!”后面有空格,而有的“.”“?”“!”后没有空格。注意gets()和scanf()的选择
#include <string.h>
#include <stdio.h>
int main()
{
char s[100010];
while (gets(s))
{
int count = 0;
int pos = 0;
int len = strlen(s);
int i, j;
for (i=0; i<len; ++i)
{
if (s[i]=='.' || s[i]=='!' || s[i]=='?')
{
++count;
while (s[pos] == ' ') {
++pos;
}
if (count == 1)
{
for (j=0; j<i+3-pos; ++j)
{
printf("*");
}
printf("\n");
}
printf("%d ",count);
for (j=pos; j<=i; ++j)
{
printf("%c",s[j]);
}
printf("\n");
pos = i+1;
}
}
printf("\n");
}
return 0;
}