Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

没过的看这里

Posted by lizimeng at 2016-08-03 20:58:40 on Problem 3617
PE的估计就是没仔细看最后的输出要求,要求80个字符一行。
算法思路很简单,能保证前面小就尽量保证前面小,相等再看后面。
贴上代码,WA可以自己写个脚本测一下。
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int i, j, n, p, q;
    char cows[2000];
    char que[2001];
    int rear;

    scanf("%d", &n);
    getchar();
    for(i=0;i<n;i++)
    {
        cows[i] = getchar();
        getchar();
    }

    i = 0;
    j = n-1;
    rear = 0;
    while(j-i>=0)
    {
        p = i;
        q = j;
        while(q-p>0 && cows[p]==cows[q])
        {
            p++;
            q--;
        }
        if(cows[p]<=cows[q])
        {
            que[rear++] = cows[i++];

        }
        else
        {
            que[rear++] = cows[j--];
        }
        if(rear==80)
        {
            que[rear++] = '\0';
            puts(que);
            rear = 0;
        }
    }
    if(rear!=0)
    {
        que[rear++] = '\0';
        puts(que);
    }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator