首页 > 代码库 > 小白书训练-Automatic Poetry

小白书训练-Automatic Poetry

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1302

题意:就是用<和>吧一句话截断为5部分,然后先打印s1s2s3s4s5,然后再输入一句话,然后在打印这句话(去除‘.’),然后打印s4s3s2s5。其实就是个模拟,没有难度,就是英语有点问题,用指针分分钟的事情。

代码:

#include <iostream>

using namespace std;

int main()
{
    char *p[5];
    char s[100];

    int N;
    cin >> N;
    cin.get();
    while(N--)
    {
        cin.getline(s,100);
        p[0] = s;
        int num = 1;

        for(char *sp = s;*sp != '\0'; sp++)
        {
            if(*sp == '<' || *sp == '>')
            {
                *sp = '\0';
                p[num++] = sp + 1;
            }
        }

        char ts[100];
        cin.getline(ts,100);
        char *sp = ts;

        while(*sp != '\0')
        {
            if(*sp == '.')
            {
                *sp = '\0';
                break;
            }
            sp++;
        }
        sp = ts;
        for(int i = 0;i < 5;i++)
        {
            cout << p[i];
        }
        cout << endl;

        cout << sp << p[3] <<  p[2] <<  p[1] <<  p[4] << endl;
    }
    return 0;
}

梦续代码:http://www.hypo.xyz

小白书训练-Automatic Poetry