第五周编程总结

第五周作业
1580769-20190329221247109-1733452217.png
输入格式:
输入为若干英文单词,每行一个,以#作为输入结束标志。其中英文单词总数不超过20个,英文单词为长度小于10的仅由小写英文字母组成的字符串。

输出格式:
输出为排序后的结果,每个单词后面都额外输出一个空格。

输入样例:
blue
red
yellow
green
purple

输出样例:
red blue green yellow purple

实验代码

include <stdio.h>

include <string.h>

main()
{
char str[20][10],t[20],str1[10];
int i,j,n=0;
while(1)
{
scanf("%s",str1);
if(str1[0]=='#')
{
break;
}
else
{
strcpy(str[n],str1);
n++;
}
}
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
{
if(strlen(str[j])>strlen(str[j+1]))
{
strcpy(t,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],t);
}
}
for(i=0;i<n;i++)
{
printf("%s ",str[i]);
}
return 0;
}

(2)流程图
1580769-20190329221419555-2083118967.jpg

(3)遇到的问题、
(1)思路转不过来,还是要找一些资料才能完成作业。
(4)运行截图
1580769-20190329221649240-1595408919.png

1580769-20190329221747103-996496609.png

(2)第五周预习作业
1580769-20190329221950856-275178935.png

1580769-20190329222025795-2127063114.png

1580769-20190329222046028-963025196.png

(3)第四周的预习

本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。

输入格式:
输入给出一行字符。

输出格式:
在一行中输出单词个数。

输入样例:
Let's go to room 209.
输出样例:
5

实验代码

include<stdio.h>

include<stdlib.h>

include<string.h>

int main()
{
int i,j=0,sign=0;
char str[10000];
gets(str);
if(str[0]!=' ')
{
sign=1;
}
for(i=0;i<strlen(str)-1;i++)
{
if(str[i]==' '&&str[i+1]!=' ')
{
sign++;
}
}
printf("%d\n",sign);
system("pause");
return 0;
}

(2)设计思路:首先给出一串字符然后在一行中输出单词个数
(3)运行图
1580769-20190329222338266-1359725511.png

(4)编程时间表
日期 博客字数 花的时间 代码行数
3.29 30 20分钟 5
3.29 180 1h 30
3.29 300 1h 50
(5)心得:感觉变化还不是挺大的,但是还是学习到了一些比如字符串,单词排序之类的。

转载于:https://www.cnblogs.com/dxl1314520/p/10624628.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值