赞
踩
实验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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。