天天看點

7-2 藏頭詩 (15分)

本題要求編寫一個解密藏頭詩的程式。

輸入格式:

輸入為一首中文藏頭詩,一共四句,每句一行。注意:一個漢字占兩個位元組。

輸出格式:

取出每句的第一個漢字并連接配接在一起形成一個字元串并輸出。同時在末尾輸入一個換行符。

輸入樣例:

一葉輕舟向東流

帆稍輕握楊柳手

風纖碧波微起舞

順水任從雅客流

輸出樣例:

一帆風順`

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (){
	int i,n=0;
	char *poem[4],str[20];
	scanf("%s",&str);
	while(n<4){
		poem[n]=(char*)malloc(sizeof(char)*strlen(str));
		strcpy(poem[n],str);
		n++;
	    scanf("%s",&str);
	}
    char mean[10];
	for(i=0;i<4;i++){
		mean[2*i]=*(poem[i]);
		mean[2*i+1]=*(poem[i]+1);
	}
	mean[2*i]='\0';
	printf("%s\n",mean);
}
           

ps:strlen統計的是位元組數,是以即使漢字占用兩個位元組也不用*2.