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

好吧,作比赛是贡献过pe。题目很简单,贴代码。

Posted by whus2010301500230 at 2012-03-25 18:53:29 on Problem 3617
/*
POJ: 3617 Best Cow Line
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>

#define MaxN 2005

using namespace std;

char str[MaxN];
char res[MaxN];
int n;

int main()
{
    //freopen("data.in", "rb", stdin);
    while(scanf("%d", &n) != EOF) {
        for(int i = 0; i < n; i++) {
            char c;
            cin >> c;
            str[i] = c;
        }
        str[n] = 0;
        int i = 0; 
        int j = n - 1;
        int k = 0;
        while(i < j) {
            if(str[i] < str[j]) {
                res[k] = str[i];
                i++;
            }
            else if(str[i] > str[j]){
                res[k] = str[j];
                j--;
            }
            else {
                int x = i + 1, y = j - 1;
                while(x < y && str[x] == str[y]) {
                    x++;
                    y--;
                }
                if(str[x] < str[y]) {
                    res[k] = str[i];
                    i++;
                }
                else {
                    res[k] = str[j];
                    j--;
                }
            }
            k++;
        }
        res[n-1] = str[i];
        res[n] = 0;
        int ans = 0;
        for(int i = 0; i < n; i++) {
            printf("%c", res[i]);
            ans++;
            if(ans % 80 == 0 && i < n - 1)
                printf("\n");
        }
    }
    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