当前位置:   article > 正文

实验11-1-9 藏尾诗 (20分)_c语言中输入为一首中文藏尾诗,一共四句。每句一行,但句子不一定是等长的,最短一个

c语言中输入为一首中文藏尾诗,一共四句。每句一行,但句子不一定是等长的,最短一个

实验11-1-9 藏尾诗 (20分)
本题要求编写一个解密藏尾诗的程序。

输入格式:
输入为一首中文藏尾诗,一共四句。每句一行,但句子不一定是等长的,最短一个汉字,最长九个汉字。注意:一个汉字占两个字节。

输出格式:
取出每句的最后一个汉字并连接在一起形成一个字符串并输出。同时在末尾输入一个换行符。

输入样例:
悠悠田园风
然而心难平
兰花轻涌浪
兰香愈幽静

输出样例:
风平浪静`

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node{
	char s[20];
	struct Node* next;
};
struct Node* create();
int main(){
	struct Node *p;
	p=create();
	while(p){
		int i=0;
		while(p->s[i]){
			i++;
		}
		printf("%c%c",p->s[i-2],p->s[i-1]);
		p=p->next;
	}
	return 0;
} 

struct Node* create(){
	struct Node* head,*tail,*p;
	head=tail=NULL;
	int count=0;
	while(count<4){
		p=(struct Node*)malloc(sizeof(struct Node));
		scanf("%s",p->s); 
		if(head==NULL){
			head=p;
		}else{
			tail->next=p;
		}tail=p;
		p->next=NULL;
		count++;
	} 
	return head;
}



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/286075?site=
推荐阅读
相关标签
  

闽ICP备14008679号