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 1079. Maximum

WA#1. Why?
Posted by harlov 8 Sep 2011 20:52
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class t1079 {

    StreamTokenizer in;
    PrintWriter out;

    void run() throws IOException
    {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    public int nextInt() throws IOException
    {
        in.nextToken();
        return (int)in.nval;
    }

    int pos_r(int v)
    {
        if (v == 1) return 1;
        else
        if (v == 0) return 0;
            else
            {
                if (v%2 == 0) return pos_r(v/2);
                    else return pos_r(v/2)+pos_r((v/2)+1);
            }
    }

    void solve() throws IOException
    {
        int n = nextInt();

        while (n!=0)
        {
            if (n == 0) out.println(0);
                else
            if (n == 1) out.println(1);
                else
            if (n % 2 == 0) out.println(pos_r(n-1));
                else out.println(pos_r(n));
            n = nextInt();
        }



    }

    public static void main(String[] args) throws IOException {

        new t1079().run();
    }

}