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 |
同一个代码,多交几次,oj的判定就不同。为什么???谢谢。。#include<stdio.h> #include<cstdlib> #include<string.h> #include<functional> #include<algorithm> using namespace std; int cmp(const void *a,const void *b) { char e,f; e=(*((char *)a)); f=(*((char *)b)); if(e>f) return 1; if(e<f) return -1; return 0; } int find2(char *a,int b) { int i=1; while(i<b) { if(a[i]<=a[i-1]) i++; else return 0; } if(i==b) return -1; } int findbig(char *a,int b) { int i; i=b-1; while(i>=0) { if(a[i]>a[i-1]) return i; else i--; } } void swap(char *a,int e,int f) { char c; c=a[e]; a[e]=a[f]; a[f]=c; } int findsmall(char *a,int e,int len) { int i,j,small; char min; i=e-1; j=e; min='z'; while(j<len) { if(a[j]>a[i]&&a[j]<min) { min=a[j]; small=j; } j++; } return small; } int main() { char content[201]; int len,find,big,small; gets(content); len=strlen(content); sort(content,content+len,less<char>()); printf("%s\n",content); while(find2(content,len)!=-1) { big=findbig(content,len); small=findsmall(content,big,len); swap(content,small,big-1); sort(content+big,content+len,less<char>()); printf("%s\n",content); } //system("pause"); return 0; } 2843526 kamel52045386 1731 Accepted 144K 77MS C++ 1268B 2007-10-29 13:03:37 2843523 kamel52045386 1731 Accepted 72K 46MS C++ 1268B 2007-10-29 13:02:19 2843500 kamel52045386 1731 Accepted 144K 77MS C++ 1268B 2007-10-29 12:54:49 2843498 kamel52045386 1731 Accepted 144K 61MS C++ 1268B 2007-10-29 12:54:45 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator