Uva's 3n+1 problem

前端 未结 8 1995
滥情空心
滥情空心 2020-12-11 22:40

I\'m solving Uva\'s 3n+1 problem and I don\'t get why the judge is rejecting my answer. The time limit hasn\'t been exceeded and the all test cases I\'ve tried have run corr

8条回答
  •  一个人的身影
    2020-12-11 23:33

    package pandarium.java.preparing2topcoder;/*
     * Main.java
     *  java program model for www.programming-challenges.com
     */
    
    import java.io.*;
    import java.util.*;
    
    class Main implements Runnable{
        static String ReadLn(int maxLg){  // utility function to read from stdin,
            // Provided by Programming-challenges, edit for style only
            byte lin[] = new byte [maxLg];
            int lg = 0, car = -1;
            String line = "";
    
            try
            {
                while (lg < maxLg)
                {
                    car = System.in.read();
                    if ((car < 0) || (car == '\n')) break;
                    lin [lg++] += car;
                }
            }
            catch (IOException e)
            {
                return (null);
            }
    
            if ((car < 0) && (lg == 0)) return (null);  // eof
            return (new String (lin, 0, lg));
        }
    
        public static void main(String args[])  // entry point from OS
        {
            Main myWork = new Main();  // Construct the bootloader
            myWork.run();            // execute
        }
    
        public void run() {
            new myStuff().run();
        }
    }
    class myStuff implements Runnable{
        private String input;
        private StringTokenizer idata;
        private List maxes;
    
        public void run(){
    
            String input;
            StringTokenizer idata;
            int a, b,max=Integer.MIN_VALUE;
    
    
            while ((input = Main.ReadLn (255)) != null)
            {
                max=Integer.MIN_VALUE;
                maxes=new ArrayList();
                idata = new StringTokenizer (input);
                a = Integer.parseInt (idata.nextToken());
                b = Integer.parseInt (idata.nextToken());
    
                System.out.println(a + " " + b + " "+max);
    
            }
        }
        private static int getCyclesCount(long counter){
            int cyclesCount=0;
            while (counter!=1)
            {
                if(counter%2==0)
                    counter=counter>>1;
                else
                    counter=counter*3+1;
                cyclesCount++;
            }
            cyclesCount++;
            return cyclesCount;
        }
        // You can insert more classes here if you want.
    }
    

提交回复
热议问题