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 |
Re:好吧,作比赛是贡献过pe。题目很简单,贴代码。In Reply To:好吧,作比赛是贡献过pe。题目很简单,贴代码。 Posted by:whus2010301500230 at 2012-03-25 18:53:29 > /* > 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator