|
|
вернуться в форумCan anyone help?Why WA! Послано daiwb 25 июн 2003 22:06 #include <iostream> using namespace std; void cout_a(int m,int n){ if(m==n) cout<<"sin("<<n<<")"; else{ cout<<"sin("<<m<<"+"; cout_a(m+1,n); cout<<")"; } } void cout_s(int m,int n){ if(m==1){ cout_a(1,1); cout<<"+"<<n; } else{ cout<<"("; cout_s(m-1,n); cout<<")"; cout_a(1,m); cout<<"+"<<n+1-m; } } int main(void){ int n; cin>>n; cout_s(n,n); cout<<endl; return 0; } Re: Can anyone help?Why WA! Послано daiwb 26 июн 2003 08:06 I know.I am using GB2312.So I see -s as –s. The following is the AC code. #include <iostream> using namespace std; void cout_a(int m,int n){ if(m==n) cout<<"sin("<<n<<")"; else{ cout<<"sin("<<m; if(m%2==1) cout<<"-"; else cout<<"+"; cout_a(m+1,n); cout<<")"; } } void cout_s(int m,int n){ if(m==1){ cout_a(1,1); cout<<"+"<<n; } else{ cout<<"("; cout_s(m-1,n); cout<<")"; cout_a(1,m); cout<<"+"<<n+1-m; } } int main(void){ int n; cin>>n; cout_s(n,n); cout<<endl; return 0; } |
|
|