标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1481 Accepted Submission(s): 552
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <map> using namespace std; int cmp(int a,int b) { return a>b; } int main() { int n,a[105]; char c[100]; while(scanf("%d",&n)!=EOF) { bool flag = false; for(int i=1; i<=n; i++) { scanf("%d",&a[i]); if(a[i]%2==1) flag = true; } if(!flag) printf("-1\n"); else { int res[105]; sort(a+1,a+n+1,cmp); if(a[n]%2==1) { for(int i=1; i<=n; i++) { res[i] = a[i]; } } else { int t = n; for(int i=n; i>=1; i--) { if(a[i]%2==1) { t = a[i]; a[i] = -1; break; } } int cnt=1; for(int i=1; i<=n; i++) { if(a[i]==-1) continue; res[cnt++] = a[i]; } res[cnt] = t; } if(res[1]==0) printf("-1\n"); else { for(int i=1; i<=n; i++) { printf("%d",res[i]); } printf("\n"); } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5649369.html