Page 4 of 4

Re: 264 - Count on Cantor

Posted: Fri Dec 26, 2014 8:19 pm
by Thorles

Code: Select all

import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,y=1,elso=1;
		while(sc.hasNext()){
			int n=sc.nextInt();
			int u=n;
			int q=1;
			while(n-q>0){
				n-=q;
				q++;
			}
			if(q%2==0) {
				x=1;
				y=q;
				for(int i=1;i<n;i++){
					x++;
					y--;
				}
			}
			else{
				x=q;
				y=1;
				for(int i=1;i<n;i++){
					y++;
					x--;
				}
			}
			if(elso==0) System.out.println();
				else elso=0;
			System.out.print("TERM " + u + " IS " + x+"/"+y);
		}
		sc.close();
	}
}
What's wrong with my code? All input i can find it gives correct answer. Please help

Re: 264 - Count on Cantor

Posted: Tue Dec 30, 2014 9:52 am
by lighted
Try to post in existing thread. Use search by problem number (264). Always print newline after last line.

Re: 264 - Count on Cantor

Posted: Sat Apr 18, 2015 9:33 pm
by shihab333
http://pastebin.com/RrdyAy5J

What is wrong with my code?? i am getting WA.. Pls Help :roll: