UVA 10361 Automatic Poetry

简单的字符串处理问题, 代码如下:


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>

#define MAXN 100
int n;
char l1[MAXN];
char l2[MAXN];
char c1[MAXN];
char c2[MAXN];
char ss[MAXN][MAXN];

int main()
{
    int i,j, ps;
    char ch;
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    getchar();
    while(n--) {
        memset(l1, 0, sizeof(l1));
        memset(l2, 0, sizeof(l2));
        memset(ss, 0, sizeof(ss));
        i = j = ps = 0;
        while((ch = getchar()) != '\n') {
            if(ch == '<') {
                ps++;
                j = 0;
            } else if(ch == '>') {
                ss[ps][j] = '\0';
                ps++;
                j = 0;
            } else if(ch != '<' && ch != '>') {
                l1[i++] = ch;
                ss[ps][j++] = ch;
            }
        }
        i = 0;
        while((ch = getchar()) != '\n') {
            if(ch != '.') l2[i++] = ch;
        }
        strcat(l2, ss[3]);
        strcat(l2, ss[2]);
        strcat(l2, ss[1]);
        strcat(l2, ss[4]);

        printf("%s\n", l1);
        printf("%s\n", l2);

    }

    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值