Ronoon
Ronoon
2017-11-22 10:42

c++程序运行时输入数据后无反应

  • c++

#include
#include
#include
using namespace std;

int main ()
{
char input,partA,**partB,**B,**outputA,**outputB;
int n,i,j,a=0,b=0,B1;

cout<<"请输入行数:"<<endl;
cin>>n;

input =new char *[n];
partA =new char *[n];
partB =new char *[n];
B =new char *[6*n];
outputA =new char *[n];
outputB = new char *[5*n];

for(i=0;i<n;++i)
   {input[i]=new char [80];
    partA[i]=new char [20];
    partB[i]=new char [70];
    B[i]=new char [20];
    outputA[i]=new char [20];
    outputB[i]=new char [20];}

cout<<"请依次输入各行:"<<endl;

for(i=0;i<n;++i)   //不知istream,input[0]被回车占据
   cin.getline(input[i],80);

for(i=0;i<n;++i)
  {   int dot;
      for(j=0;j<80;++j)
        {if(input [i][j]==' '&&input[i][j+1]=='-'&&input[i][j+2]=='>') break;
        partA[i][j]=input[i][j];}

      dot=j+4;

      for(j=j+4;j<80;++j)       //
        {if (input[i][j]==' '&&input[i][j+1]==' ') break;
         partB[i][j-dot]=input[i][j];}
  }

 for(i=0;i<n;++i) delete []input[i];
 delete []input;

for(i=0;i<n;++i)
  {for(int k=i;k>=0;--k)
    { int w=0;
        if(!strcmp(partA[i],partA[k])) {++w;break;}
   if (w=0) {outputA[a]=partA[i];++a;} //
    }
  }

for (i=0;i<n;++i) delete [] partA[i];
delete []partA;

for(i=0;i<n;++n)
  {for(j=0;j<=70;++j)
     {int counter1=0,counter2=0;
      if(partB[i][j]==' '&&partB[i][j+1]==' ') {B1=counter1;break;}
      if(partB[i][j]==' ') ++counter1;
        else {B[counter1][counter2]=partB[i][j];  //
              ++counter2;}
     }
  }
  for (i=0;i<n;++i) delete [] partB[i];
delete []partB;

for(i=0;i<=B1;++i)
  {for(int k=i;k>=0;--k)
     {int w=0;
       if(!strcmp(B[i],B[k])) {++w;break;}
   if (w=0) {outputB[b]=B[i];++b;}
     }
  }
  for (i=0;i<=B1;++i) delete [] B[i];
delete []B;

cout<<"A部分单词:"<<endl;
for(i=0;i<a;++i) cout<<left<<setw(12)<<partA[i];
cout<<endl;
cout<<"B部分单词:"<<endl;
for(i=0;i<b;++i) cout<<left<<setw(12)<<B[i];

for (i=0;i<b;++i) delete [] outputB[i];
delete []outputB;
for (i=0;i<a;++i) delete [] outputA[i];
delete []outputA;

return 0;

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答