当前位置:网站首页>Pat class B 1009 C language
Pat class B 1009 C language
2022-06-23 05:53:00 【Octopus bro】
1009. irony (20)
Give me an English sentence , Ask you to write a program , Reverse the order of all the words in the sentence .
Input format : The test input contains a test case , The total length given in one line does not exceed 80 String . A string consists of several words and spaces , The words are made of English letters ( There is a distinction between case and case ) Composed string , Use... Between words 1 Separate the spaces , Type to make sure there are no extra spaces at the end of the sentence .
Output format : The output of each test case takes up one line , Output the sentences in reverse order .
sample input :Hello World Here I Comesample output :
Come I Here World Hello
Ideas : Look for the blank space in the input sentence from the back to the front , Use here strtchr function , This function looks for a character from right to left , Find the pointer that returns the character , No return found NULL. After finding the space, assign the space as ‘\0’, It is equivalent to separating the last word from the previous sentence . Add one more pointer , Point to the first letter of the truncated word , Then output the string starting from the pointer position , That is, the output is the last word .
One 、 Starting variable
1. character string array.
2. A pointer that accepts a space address
Two 、 operation
1. Accept string
2. Look for spaces from the end of the string
3. Find a space and put this position ‘\0’, And add one to the pointer
4. Output the string opened from the pointer position
3、 ... and 、 Code
#include "stdio.h"
#include "string.h"
int main()
{
char array[81];
gets(array);//1. Accept string
char * p;
int i;
for(i = strlen(array) - 1; i >= 0; i--,i = strlen(array) - 1)
{
p = strrchr(array,' ');//2. Look for spaces from the end of the string , If no space is found, return NULL
if(!p)
{
printf("%s",array);
break;
}// If p It's empty , This indicates that the string has been traversed
*p = '\0';//3. Find a space and put this position ‘\0’, And add one to the pointer
p++;
printf("%s ",p);//4. Output the string opened from the pointer position
}
return 0;
},
边栏推荐
- Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time
- 数字藏品火热背后需要强大的技术团队支持 北方技术团队
- Prometheus, incluxdb2.2 installation and flume_ Export download compile use
- opencv显示图像
- Leetcode topic resolution divide two integers
- PAT 乙等 1023 组个最小数
- 数字藏品市场才刚刚开始
- Raspberry pie assert preliminary exercise
- Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
- 新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!
猜你喜欢

数字化工厂建设可划分为三个方面

jvm-05.垃圾回收

Visdom draws multiple dynamic loss curves

ArcTime 制作中英文字幕视频

如何指定pig-register项目日志的输出路径

A bit of knowledge - folding forging and Damascus steel

数字藏品火热背后需要强大的技术团队支持 北方技术团队

Digital collections - new investment opportunities

Adnroid activity截屏 保存显示到相册 View显示图片 动画消失

Prometheus, incluxdb2.2 installation and flume_ Export download compile use
随机推荐
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale
AHA C language Chapter 7 you can do more with it (talks 27-28)
Pit filling for abandoned openssl-1.0.2 (.A to.So)
Basic calculator II for leetcode topic analysis
What is the magic of digital collections? Which reliable teams are currently developing
数字藏品赋能实体产业释放了哪些利好?
Behind the hot digital collections, a strong technical team is needed to support the northern technical team
PAT 乙等 1025 反转链表
Leetcode topic resolution divide two integers
Wechat applet: production and generation of love guarantee
Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
Centos7 installation of postgresql8.2.15 and creation of stored procedures
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
Wechat applet: unfashionable love talk
What does the English letter PC mean? What does the Internet PC mean
Real MySQL interview question (30) -- shell real estate order analysis
阿里云对象存储oss+picgo+typora实现构建图床
PAT 乙等 1021 个位数统计
Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql