1
回答
上次的题数组越界了....
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

还是上次的题,换了一个思路编,就悲剧了。老是打印出来“烫”,“?”,老师和同学说可能是数组越界了,怎么办啊? 调了5个小时了啊。

#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<ctype.h>

void main(void)
{
 char a[1024];
 char b[1024][100];
 int c[1024];
 int i;
 int j = 0;
 int k = 0;
 int m = 0;
 int charLength;
 int counter = 0;
 int counter1 = 0;
 int max = 0;
 int x;
 
 cout<<"输入串:(Enter结束输入。)"<<endl;
 cin.getline( a, 1024, '\n' );
 charLength = strlen(a);
 
 for( i = 0; i < charLength; i++ )
 {
  while( a[i] != '\0' )
  {
   while( isdigit( a[i] ) )
   {
    while( j <= 1024 )
    {
     while( a[i] != '\0' )
     {
      while( k <= 1024 )
      {
       while( a[i] != '\0' )
       {
        if( !isdigit( a[i] ) )
        {
         break;
        }
        else
        {
         b[j][k] = a[i];
         i++;
         counter++;
        }
        k++;
       }
       c[m] = counter;
       m++;
       while( counter > max )
       {
        max = counter;
        counter = 0;
       }
       if( !isdigit( a[i] ) || a[i] == '\0' )
       {
        j++;
        break;
       }
       else
       {
        i++;
       }
       i++;
      }
      k = 0; 
      counter1++;
      break;
     }
     break;
    }
   }
   break;
  }
 }
 cout<<"输出结果:"<<endl;
 
 m = j;
 for( j = 0; j < counter1; j++ )
 {
  x = max - c[j] + 1;
  cout<<setw(x)<<setfill(' ');
  for( k = 0; k < c[j]; k++ ) 
  {
   cout<<setiosflags(ios::right)<<b[j][k];
  }
  
  cout<<endl;
 }
 
 cout<<endl;
 
}
举报
亓明昊
发帖于6年前 1回/298阅
顶部