如果像下面这样,需要加什么吗(不改变其他输出结果)
【样例输入】
the. chinese mainland reported 526 . confirmed cases and 894 asymptomatic . cases for Saturday.
【样例输出】
The. Chinese mainland reported 526 . Confirmed cases and 894 asymptomatic . Cases for saturday.
你的问题是什么?代码完整么?
仅供参考,谢谢!若有问题多谢提出来!
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define N 1000
static char *set = ".!?…";
static char *set1 = " ";
char s[N];
// 去掉多余空格
void delSpace(char *s)
{
if (!s)
return;
char *p1 = s, *p2 = s + strlen(s), *p;
// 在这里开头的空格不删除
// 因为句开头本来就要留空格的
while (*p1 == ' ' && p1 < p2)
p1++;
// 如果连续两个空格以上则只留一个空格
while (p1 < p2)
{
p = p1;
while (*p1 == ' ' && *(p1 + 1) == ' ')
p1++;
memcpy(p, p1, p2 - p1 + 1);
p1++;
}
}
// 每句首字母大写
void FirstCToUpper(char *s)
{
if (!s)
return;
// 当字符串没有标点符号时,让第一次出现的小写字母转换成大写字母
if (strcspn(s, set) == strlen(s))
{
// 开头可能有空格要考虑
int n = strspn(s, set1);
if (islower(*(s + n)))
*(s + n) = toupper(*(s + n));
return;
}
char *p = s, *p1, *p2;
int n = 0, len = strlen(s);
// 定位第一个句号
while ((p1 = strpbrk(p, set)) && p < s + len - 1)
{
n = strspn(p, set1);
if (islower(*(p + n)))
*(p + n) = toupper(*(p + n));
p = p1 + 1;
}
}
int main(void)
{
scanf("%999[^\n]", s);
FirstCToUpper(s);
delSpace(s);
puts(s);
return 0;
}