264 - Count on Cantor

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Thorles
New poster
Posts: 1
Joined: Fri Dec 26, 2014 8:17 pm

Re: 264 - Count on Cantor

Post 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
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 264 - Count on Cantor

Post by lighted »

Try to post in existing thread. Use search by problem number (264). Always print newline after last line.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
shihab333
New poster
Posts: 1
Joined: Sat Apr 18, 2015 9:25 pm

Re: 264 - Count on Cantor

Post by shihab333 »

http://pastebin.com/RrdyAy5J

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

Return to “Volume 2 (200-299)”