ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1149. Sinus Dances

Can anyone help?Why WA!
Posted by daiwb 25 Jun 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!
Posted by daiwb 26 Jun 2003 08:06
I know.I am using GB2312.So I see -s as &#8211;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;
}