UVaOJ 10361 - Automatic Poetry

#include <stdio.h>
#include <string.h>
char line1[200];
char line2[200];
//#define DEBUG
int main()
{
	int n = 0;
	scanf("%d\n", &n);//如果scanf("%d", &n)这样写,输入完数字之后回车,会导致回车暂存在输入缓存区
	//当接着调用fgets时,会读入一个空行即"\n\0";如接着调用的是gets,则读入的是空字符串"\0"
	while (n--)
	{
		memset(line1, '\0', sizeof(line1));
		memset(line2, '\0', sizeof(line2));
		//fgets(line1, sizeof(line1), stdin);
		//fgets(line2, sizeof(line2), stdin);//fgets写入line1缓存区的字符串,包括行末的'\n'!
		gets(line1);//gets写入line1缓存区的字符串,忽略了行末的'\n'。
		//gets有缓存区溢出的陷阱,但是注意小心就好!
		gets(line2);
#ifdef DEBUG
		printf("[%s]\n", line1);
		printf("[%s]\n", line2);
#endif
		char *p1 = strchr(line1, '<') + 1;
		char *p2 = strchr(line1, '>') + 1;
		char *p3 = strrchr(line1, '<') + 1;
		char *p4 = strrchr(line1, '>') + 1;
		*(p1 - 1) = '\0';
		*(p2 - 1) = '\0';
		*(p3 - 1) = '\0';
		*(p4 - 1) = '\0';

		char *tmp = NULL;
		while ((tmp = strchr(line2, '.')) != NULL)
		{
			if (*(tmp + 1) == '.' && *(tmp + 2) == '.')
			{
				*tmp = '\0';
				break;
			}
		}

#ifdef DEBUG
		printf("%s %s %s %s %s\n", line1, p1, p2, p3, p4);
#endif
		printf("%s%s%s%s%s\n", line1, p1, p2, p3, p4);
		printf("%s%s%s%s%s\n", line2, p3, p2, p1, p4);
		
		memset(line1, '\0', sizeof(line1));
		memset(line2, '\0', sizeof(line2));
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值