Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么RUNTIME ERROR啊,在VC下调没有问题啊

Posted by goldenlock at 2004-10-11 17:51:16 on Problem 1256
用递归回溯,已经通过了,可稍做改动,改为跌带回溯,我调试是和用递归的结果一样,可为什么一提交就RUNTIME ERROR啊
#include <iostream.h>
char a[20];   //存接收的字符串          
int b[20][20];  //用于在交换之前保存原串
int c[20];     //由于记录每层以遍历的的情况,遍历完一棵子树后加1
int length;    //接收的字符串长度
int n;
template<class Elem>
inline void swap(Elem &e1, Elem &e2) {
  Elem temp = e1;
  e1 = e2;
  e2 = temp;
}
int convert(char s)
{
if(s>='A'&&s<='Z')
return (s-'A')*2;
if(s>='a'&&s<='z')
return (s-'a')*2+1;
return int(s);
} 
void sort(char* s,int len)
{
  int i,j;
  int temp1,temp2;
  for(i=0;i<len-1;i++)
  for(j=0;j<len-1-i;j++)
    {    
    temp1=convert(s[j]);
    temp2=convert(s[j+1]); 
     if(temp1>temp2)
     swap(s[j],s[j+1]);
     }
    }
  //int sum;
  void create(int l)                     //l代表层数          
{
   int i,j,k;
   for(i=0;i<=length-2;i++)             //初始化
   c=i;
      while(c[0]!=length)               //当第0层即根的所有子树全搜索过后结束
    {
       if(c[l]<length&&l<length-1)
       {
            for(k=l;k<c[l];k++)
            if(a[k]==a[c[l]])
            break;
    if(k==c[l])
          {
            for(j=l;j<length;j++)          //复制保存 copy()
            b[l][j]=a[j];
            swap(a[l],a[c[l]]);
            sort(a+l+1,length-l-1);
            l++;
         }
   else
   c[l]++;
        }
        else if(l==length-1)            //打印结果,退到上层
             {
              for(k=0;k<length;k++)
       cout<<a[k];
              cout<<endl;
    //          sum++;
              l--;
             // for(j=l;j<length;j++)
             // a[j]=b[l][j];
              c[l]++;
              }
        else                            //退到上层
               {
                 l--;
   c[l]++;
   if(c[l]<length)
   {
   for(j=l;j<length;j++)   //copy( )back
                 a[j]=b[l][j];
                 }
                 c[l+1]=l+1; //清为l+1,以便到同层的右面分支时使用
                }
     }            
}
void main( )
{
int i;
char ch;
cin>>n;
ch=cin.get( );
for(i=0;i<n;i++)
{
int j=0;
while((ch=cin.get( ))!='\n')
{
a[j]=ch;
j++;
  }
length=j;
sort(a,length);
create(0);
// cout<<sum<<endl;
}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator