| ||||||||||
| 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:总是Runtime error,我用了很多指针,但是我在VC6里运行得很好,结果完全正确,算法我保证是对的,但是总是不能accepted.In Reply To:总是Runtime error,我用了很多指针,但是我在VC6里运行得很好,结果完全正确,算法我保证是对的,但是总是不能accepted. Posted by:Jeff_Zhang at 2005-11-03 14:17:53 >
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> #define numString 100
> #define lenString 50
>
> typedef struct
> {
> char *p;
> int key;
> }strDNA;
>
> int getKey(char p[],int n) //得到mesure值
> {
> int j,key = 0;
> char *temp;
> for( int i = 0; i < n-1;p++, i ++)
> {
> for (temp = p + 1,j = i +1;j < n;temp ++,j++)
> {
> if( *p > *temp)
> {
> key ++;
> }
> }
> }
> return key;
> }
>
> void bubblesort(strDNA p[],int n) //稳定排序方法,冒泡排序
> {
> int i,j,tag;
> strDNA temp;
> for( i=0,tag=1; tag ==1 && i < n-1; i++)
> {
> tag = 0;
> for (j = 0; j < n-i-1; j ++)
> {
> if(p[j].key > p[j+1].key)
> {
> temp = p[j];
> p[j] = p[j+1];
> p[j+1] = temp;
> tag = 1;
> }
> }
> }
> }
>
>
>
> int main ()
> {
> int m,n,i=0;
> cin>>n>>m;
> strDNA dna[numString];
> string temp;
> for (i = 0; i < n;i++)
> {
> dna[i].p = new char;
> cin>>temp;
> strcpy(dna[i].p,temp.c_str ());
>
> }
> for ( i = 0; i < m; i ++)
> {
> dna[i].key = getKey(dna[i].p,n);
> }
>
> bubblesort(dna,m);
> cout<<endl;
>
> for( i = 0; i < m ; i ++ )
> {
> cout<<dna[i].p<<endl;
>
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator