博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第五周编程总结
阅读量:4705 次
发布时间:2019-06-10

本文共 1256 字,大约阅读时间需要 4 分钟。

第五周作业

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

你可能感兴趣的文章
C#发现之旅(收藏)
查看>>
POJ1125 Stockbroker Grapevine 多源最短路
查看>>
HDU 2126 Buy the souvenirs
查看>>
html5 Game开发系列文章之 一 精灵(上)
查看>>
整理自己的.net工具库
查看>>
mysql user表root 用户误删除解决方法
查看>>
servlet中参数的传递及如何防止出现中文乱码
查看>>
Hibernate分页
查看>>
SQLyog v11.24查询MySQL5.6.24中文乱码的解决方法
查看>>
顺序容器的insert使用方法
查看>>
彩色图像--图像增强 直方图增强
查看>>
IOS启动其他应用程序
查看>>
Hadoop-1.1.2、HBase-0.94.7完全分布式集群结构
查看>>
hdu 1698
查看>>
Session变量不能转移到下页.解决: session.use_trans_sid = 1
查看>>
CMap与hash_map效率对照
查看>>
为开发用途mac电脑瘦身
查看>>
Android中GridView的一些特殊属性
查看>>
DBUtils、QueryRunner的query/update/batch、ResultSetHandler的9个处理器、ThreadLocal管理conn进行事务处理的案例...
查看>>
如何调整DOS窗口的宽高
查看>>