|
|
back to boardCompilation error Posted by Yuri 9 Feb 2002 02:48 What's going on?! I've now any errors and warnings. I'm using only <iostream.h>. Re: Compilation error Posted by Yuri 9 Feb 2002 02:50 > What's going on?! > I've now any errors and warnings. > I'm using only <iostream.h>. #include <iostream.h> int main(void) { unsigned int n; cin>>n; char *a,*val; unsigned int na; a=new char[2000]; val=new char[4]; if(n==0) { cout<<'0'; return 0; } a[0]='s'; a[1]='i'; a[2]='n'; a[3]='('; a[4]='1'; a[5]=')'; a[6]=0; na=6; unsigned int j; for(unsigned int i=0;i<n-1;i++) cout<<'('; for(unsigned int i=2;i<=n;i++){ cout<<a; cout<<'+'; cout<<(n-i+2); cout<<')'; //изменение а na=na-i+1; //игнорируем скобки справа if((i % 2)==0) a[na]=(char)'-'; else a[na]='+'; a[na+1]='s'; a[na+2]='i'; a[na+3]='n'; a[na+4]='('; na+=5; if(i<10){ val[0]=(char)('0'+i); val[1]=0; } else if(i<100) { val[0]=(char)('0'+i/10); val[1]=(char)('0'+i-i/10*10); val[2]=(char)0; } else { val[0]=(char)('0'+i/100); val[1]=(char)('0'+(i-i/100*100)/10); val[2]=(char)('0'+i-i/10*10); val[3]=(char)0; } j=0; while(val[j]!=0){ a[na]=val[j]; j++; na++; } for(j=0;j<i;j++) a[na+j]=')'; na+=j; a[na]=0; } cout<<a; cout<<"+1"; return 0; } > Re: Compilation error Posted by afo 19 Mar 2002 17:32 > > What's going on?! > > I've now any errors and warnings. > > I'm using only <iostream.h>. > #include <iostream.h> > > int main(void) > { > unsigned int n; > cin>>n; > char *a,*val; > unsigned int na; > > a=new char[2000]; > val=new char[4]; > > if(n==0) > { > cout<<'0'; > return 0; > } > > a[0]='s'; > a[1]='i'; > a[2]='n'; > a[3]='('; > a[4]='1'; > a[5]=')'; > a[6]=0; > na=6; > > unsigned int j; > > for(unsigned int i=0;i<n-1;i++) //~~~~~~~~~~~~~~~ > cout<<'('; > > for(unsigned int i=2;i<=n;i++){ //~~~~~~~~~~~~~~~redefinition > cout<<a; > cout<<'+'; > > cout<<(n-i+2); > cout<<')'; > > //§Ъ§Щ§Ю§Ц§Я§Ц§Я§Ъ§Ц §С > na=na-i+1; //§Ъ§Ф§Я§а§в§Ъ§в§е§Ц§Ю §г§Ь§а§Т§Ь§Ъ §г§б§в§С§У§С > if((i % 2)==0) > a[na]=(char)'-'; > else > a[na]='+'; > a[na+1]='s'; > a[na+2]='i'; > a[na+3]='n'; > a[na+4]='('; > na+=5; > if(i<10){ > val[0]=(char)('0'+i); > val[1]=0; > } > else if(i<100) > { > val[0]=(char)('0'+i/10); > val[1]=(char)('0'+i-i/10*10); > val[2]=(char)0; > } > else > { > val[0]=(char)('0'+i/100); > val[1]=(char)('0'+(i-i/100*100)/10); > val[2]=(char)('0'+i-i/10*10); > val[3]=(char)0; > } > j=0; > while(val[j]!=0){ > a[na]=val[j]; > j++; > na++; > } > for(j=0;j<i;j++) > a[na+j]=')'; > na+=j; > > a[na]=0; > } > > cout<<a; > cout<<"+1"; > > return 0; > } > > > Re: Compilation error Posted by Sylap 7 Oct 2012 01:29 THIS CODE WILL LEAD YOU TO AC (PAY ATTENTION TO CORRECTIONS): #include <iostream> //not # include <iostream.h> using namespace std; //to be able to use cin,cout and many other functions int main(void) { unsigned int n; cin>>n; char *a,*val; unsigned int na; a=new char[2000]; val=new char[4]; if(n==0) { cout<<'0'; return 0; } a[0]='s'; a[1]='i'; a[2]='n'; a[3]='('; a[4]='1'; a[5]=')'; a[6]=0; na=6; unsigned int j; for(unsigned int i=0;i<n-1;i++) cout<<'('; for(unsigned int i=2;i<=n;i++){ cout<<a; cout<<'+'; cout<<(n-i+2); cout<<')'; //изменение а na=na-i+1; //игнорируем скобки справа if((i % 2)==0) a[na]=(char)'-'; else a[na]='+'; a[na+1]='s'; a[na+2]='i'; a[na+3]='n'; a[na+4]='('; na+=5; if(i<10){ val[0]=(char)('0'+i); val[1]=0; } else if(i<100) { val[0]=(char)('0'+i/10); val[1]=(char)('0'+i-i/10*10); val[2]=(char)0; } else { val[0]=(char)('0'+i/100); val[1]=(char)('0'+(i-i/100*100)/10); val[2]=(char)('0'+i-i/10*10); val[3]=(char)0; } j=0; while(val[j]!=0){ a[na]=val[j]; j++; na++; } for(j=0;j<i;j++) a[na+j]=')'; na+=j; a[na]=0; } cout<<a; cout<<"+1"; return 0; } Edited by author 07.10.2012 01:31 Edited by author 07.10.2012 01:31 |
|
|