| ||||||||||
| 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向中间搜索In Reply To:跪求各位!!!帮帮我,怎么设计算法?当两边相等的时候怎么办?我这猪头实在是想不出来 Posted by:suying at 2008-07-20 16:51:37 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char a[10009],b[10009],ch;
int n;
int test(int i,int j)
{
int i1,j1;
for(i1=i+1,j1=j-1;i1<j1;i1++,j1--)
{
if(a[i1]>a[j1])
return j;
if(a[i1]<a[j1])
return i;
}
return i;
}
void cometonew()
{
int i,j,kk=0;
for(i=0,j=strlen(a)-1;i<=j; )
{
if(a[i]<a[j])
{
b[kk++]=a[i];
i++;
}
else if(a[i]>a[j])
{
b[kk++]=a[j];
j--;
}
else
{ int pp=test(i,j);
b[kk++]=a[pp];
if(pp==i)
i++;
else
j--;
}
}
b[kk]='\0';
}
int main(int argc, char *argv[])
{
int i,j;
cin>>n;
getchar();
for(i=0;i<n;i++)
scanf("%c%c",&a[i],&ch);
cometonew();
j=strlen(b);
for(i=0;i<j;i++)
{
printf("%c",b[i]);
if((i+1)%80==0||i==j-1)
printf("\n");
}
system("PAUSE");
return EXIT_SUCCESS;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator