Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
没过的看这里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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator