第五周作业
输入格式: 输入为若干英文单词,每行一个,以#作为输入结束标志。其中英文单词总数不超过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)流程图
(3)遇到的问题、
(1)思路转不过来,还是要找一些资料才能完成作业。 (4)运行截图(2)第五周预习作业
(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)运行图(4)编程时间表
日期 博客字数 花的时间 代码行数 3.29 30 20分钟 5 3.29 180 1h 30 3.29 300 1h 50 (5)心得:感觉变化还不是挺大的,但是还是学习到了一些比如字符串,单词排序之类的。