7-13 单词首字母大写 (15 分)
时间: 2023-04-26 20:04:05 浏览: 63
7-13 单词首字母大写:
1. Monday
2. Tuesday
3. Wednesday
4. Thursday
5. Friday
6. Saturday
7. Sunday
8. January
9. February
10. March
11. April
12. May
13. June
相关问题
PTA7-3 单词首字母大写
以下是Python实现单词首字母大写的代码:
```python
s = input() # 输入句子
result = ""
for sentence in s.split("."): # 以句号为分隔符分割句子
for sub_sentence in sentence.split("?"): # 以问号为分隔符分割子句
for sub_sub_sentence in sub_sentence.split("!"): # 以感叹号为分隔符分割子子句
if sub_sub_sentence.strip() != "": # 去除空格后判断是否为空
result += sub_sub_sentence.strip()[0].upper() + sub_sub_sentence.strip()[1:] + " " # 将首字母大写后加入结果字符串
print(result[:-1]) # 输出结果字符串,去除最后一个空格
```
c语言单词首字母大写
以下是两种C语言单词首字母大写的例子:
1.在一行中输出已输入的字符,其中所有单词的首字母已改为大写。
```c
#include <stdio.h>
int main(int argc, char *argv[]) {
char ch;
ch=getchar();
int flag=1;//首字母大写标志
while(ch!='\n') {
if(ch>='a'&&ch<='z'&&flag==1)//小写字母并且有大写字母标志,则大写
{
ch=ch-32;
putchar(ch);
}
else {
putchar(ch);
}
if(ch==' ')//空格标志下一个字母要大写
flag=1;
else
flag=0;
ch=getchar();
}
return 0;
}
```
2.字符串首字母转换成大写简单实例
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
char input[] = "this is a book";
char output[256] = {'\0'};
int i = 0;
int j = 0;
int len = strlen(input);
for(i = 0; i < len; i++)
{
if(i == 0 || input[i - 1] == ' ')
{
output[j++] = toupper(input[i]);
}
else
{
output[j++] = input[i];
}
}
printf("%s\n", output);
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)