Page 1 of 2

11947 - Cancer or Scorpio

Posted: Fri Sep 09, 2011 6:50 pm
by sijan
I try my best..But cant understand about d bug. Plzz help me.

Code: Select all

 Code deleted after AC..:D

Code: Select all

[code]
[/code]

Re: 11947 - Cancer or Scorpio

Posted: Fri Sep 09, 2011 11:39 pm
by sijan
I got ac...:D

Problem with the problem "Cancer or Scorpio"

Posted: Wed Oct 10, 2012 5:49 pm
by shondhi
In this problem, will I need to write code for all zodiac sign? or Just write the code for only Cancer or Scorpio sign?

Re: Problem with the problem "Cancer or Scorpio"

Posted: Wed Oct 10, 2012 6:48 pm
by brianfry713
Next time post the problem number 11947.
Code all the zodiac signs.

11947 - Cancer or Scorpio

Posted: Thu Feb 14, 2013 3:39 am
by ok_woei
I keep getting WA for the problem. Can't really see where is the bug. Please help.

Code: Select all

Remove after AC

Re: 11947 - Cancer or Scorpio

Posted: Thu Feb 14, 2013 6:25 am
by lbv
ok_woei wrote:I keep getting WA for the problem. Can't really see where is the bug. Please help.
Check the spelling of pisces.

Re: 11947 - Cancer or Scorpio

Posted: Thu Feb 14, 2013 7:01 am
by ok_woei
Thx.. that was the worst mistake!!

Re: 11947 - Cancer or Scorpio

Posted: Sat Apr 27, 2013 12:50 am
by justadreamer
Can anyone point me at a mistake in this code, please. It works fine on test cases from the problem, also I tested Capricorn test case. triple checked the zodiac sign spelling,etc. I am stuck...

Code: Select all

import java.util.*;

public class Main {
	private class Sign {
		public String name;
		public GregorianCalendar start;
		public GregorianCalendar end;

		public Sign(String name, int start_month, int start_day, int end_month, int end_day) {
			this.name = name;
			start = new GregorianCalendar(1970,start_month-1,start_day);
			end = new GregorianCalendar(1970,end_month-1,end_day);
		}

		public boolean isDateWithinSign(GregorianCalendar d) {
			int year = d.get(Calendar.YEAR);
			start.set(Calendar.YEAR,year);
			end.set(Calendar.YEAR,year);
			return start.compareTo(d)<=0 && d.compareTo(end)<=0;
		}
	}

	private Sign [] signs = {
		new Sign("Aquarius",1, 21, 2, 19),
		new Sign("Pisces",2, 20,3, 20),
		new Sign("Aries",3, 21,4, 20),
		new Sign("Taurus",4, 21,5, 21),
		new Sign("Gemini",	 5, 22,	 6, 21),
		new Sign("Cancer",	 6, 22,	7, 22),
		new Sign("Leo",	 7, 23,	 8, 21),
		new Sign("Virgo", 8, 22,	 9, 23),
		new Sign("Libra",	 9, 24,	 10, 23),
		new Sign("Scorpio",	 10, 24,11, 22),
		new Sign("Sagittarius",	 11, 23,12, 22),
		new Sign("Capricorn",	 12, 23,12, 31),
		new Sign("Capricorn",	 1, 1,1, 20)
	};
	
	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.calc();
	}

	public void calc() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();

		for (int i=0;i<N;i++) {
			String dateString = scanner.next();
			int m = Integer.parseInt(dateString.substring(0,2));
			int d = Integer.parseInt(dateString.substring(2,4));
			int y = Integer.parseInt(dateString.substring(4));
			GregorianCalendar calendar = new GregorianCalendar(y,m-1,d);
			calendar.add(Calendar.DAY_OF_MONTH, 40*7);
			String signName = "";
			for (Sign sign : signs) {
				if (sign.isDateWithinSign(calendar)) {
					signName = sign.name.toLowerCase();
					break;
				}
			}

			System.out.println((i+1)+" "+
				(calendar.get(Calendar.MONTH)+1)+"/"+
				calendar.get(Calendar.DAY_OF_MONTH)
				+"/"+calendar.get(Calendar.YEAR)+
				" "+signName);
		}
	}
}

Re: 11947 - Cancer or Scorpio

Posted: Fri May 17, 2013 3:50 am
by brianfry713

Wrong Answer: 11947 - Cancer or Scorpio

Posted: Thu Nov 14, 2013 2:56 am
by raj
I cant see the bug can anyone please help me... :( :( :(

Code: Select all

import java.io.*;
import java.util.*;
public class Main{
	public static GregorianCalendar Scor1 = new GregorianCalendar();
	public static GregorianCalendar Scor2 = new GregorianCalendar();
	public static GregorianCalendar aq1 = new GregorianCalendar();
	public static GregorianCalendar aq2 = new GregorianCalendar();
	public static GregorianCalendar pi1 = new GregorianCalendar();
	public static GregorianCalendar pi2 = new GregorianCalendar();
	public static GregorianCalendar ari1 = new GregorianCalendar();
	public static GregorianCalendar ari2 = new GregorianCalendar();
	public static GregorianCalendar ta1 = new GregorianCalendar();
	public static GregorianCalendar ta2 = new GregorianCalendar();
	public static GregorianCalendar ge1 = new GregorianCalendar();
	public static GregorianCalendar ge2 = new GregorianCalendar();
	
	public static GregorianCalendar can1 = new GregorianCalendar();
	public static GregorianCalendar can2 = new GregorianCalendar();
	public static GregorianCalendar cap1 = new GregorianCalendar();
	public static GregorianCalendar cap2 = new GregorianCalendar();
	public static GregorianCalendar le1 = new GregorianCalendar();
	public static GregorianCalendar le2 = new GregorianCalendar();
	
	public static GregorianCalendar ver1 = new GregorianCalendar();
	public static GregorianCalendar ver2 = new GregorianCalendar();
	public static GregorianCalendar lib1 = new GregorianCalendar();
	public static GregorianCalendar lib2 = new GregorianCalendar();
	public static GregorianCalendar sag1 = new GregorianCalendar();
	public static GregorianCalendar sag2 = new GregorianCalendar();
	
	public static void set(int year){
		Scor1.set(GregorianCalendar.MONTH,9); //9 means october
		Scor1.set(GregorianCalendar.DATE,24);
		Scor1.set(GregorianCalendar.YEAR,year);
		Scor2.set(GregorianCalendar.MONTH,10); //9 means october
		Scor2.set(GregorianCalendar.DATE,22);
		Scor2.set(GregorianCalendar.YEAR,year);
		
		aq1.set(GregorianCalendar.MONTH,0); //9 means october
		aq1.set(GregorianCalendar.DATE,21);
		aq1.set(GregorianCalendar.YEAR,year);
		aq2.set(GregorianCalendar.MONTH,1); //9 means october
		aq2.set(GregorianCalendar.DATE,19);
		aq2.set(GregorianCalendar.YEAR,year);
		
		pi1.set(GregorianCalendar.MONTH,1); //9 means october
		pi1.set(GregorianCalendar.DATE,20);
		pi1.set(GregorianCalendar.YEAR,year);
		pi2.set(GregorianCalendar.MONTH,2); //9 means october
		pi2.set(GregorianCalendar.DATE,20);
		pi2.set(GregorianCalendar.YEAR,year);
		
		ari1.set(GregorianCalendar.MONTH,GregorianCalendar.MARCH); //9 means october
		ari1.set(GregorianCalendar.DATE,21);
		ari1.set(GregorianCalendar.YEAR,year);
		ari2.set(GregorianCalendar.MONTH,GregorianCalendar.APRIL); //9 means october
		ari2.set(GregorianCalendar.DATE,20);
		ari2.set(GregorianCalendar.YEAR,year);
		
		ta1.set(GregorianCalendar.MONTH,GregorianCalendar.APRIL); //9 means october
		ta1.set(GregorianCalendar.DATE,21);
		ta1.set(GregorianCalendar.YEAR,year);
		ta2.set(GregorianCalendar.MONTH,GregorianCalendar.MAY); //9 means october
		ta2.set(GregorianCalendar.DATE,21);
		ta2.set(GregorianCalendar.YEAR,year);
		
		ge1.set(GregorianCalendar.MONTH,GregorianCalendar.MAY); //9 means october
		ge1.set(GregorianCalendar.DATE,22);
		ge1.set(GregorianCalendar.YEAR,year);
		ge2.set(GregorianCalendar.MONTH,GregorianCalendar.JUNE); //9 means october
		ge2.set(GregorianCalendar.DATE,21);
		ge2.set(GregorianCalendar.YEAR,year);
		
		can1.set(GregorianCalendar.MONTH,GregorianCalendar.JUNE); //9 means october
		can1.set(GregorianCalendar.DATE,22);
		can1.set(GregorianCalendar.YEAR,year);
		can2.set(GregorianCalendar.MONTH,GregorianCalendar.JULY); //9 means october
		can2.set(GregorianCalendar.DATE,22);
		can2.set(GregorianCalendar.YEAR,year);
		
		le1.set(GregorianCalendar.MONTH,GregorianCalendar.JULY); //9 means october
		le1.set(GregorianCalendar.DATE,23);
		le1.set(GregorianCalendar.YEAR,year);
		le2.set(GregorianCalendar.MONTH,GregorianCalendar.AUGUST); //9 means october
		le2.set(GregorianCalendar.DATE,21);
		le2.set(GregorianCalendar.YEAR,year);
		
		ver1.set(GregorianCalendar.MONTH,GregorianCalendar.AUGUST); //9 means october
		ver1.set(GregorianCalendar.DATE,22);
		ver1.set(GregorianCalendar.YEAR,year);
		ver2.set(GregorianCalendar.MONTH,GregorianCalendar.SEPTEMBER); //9 means october
		ver2.set(GregorianCalendar.DATE,23);
		ver2.set(GregorianCalendar.YEAR,year);
		
		lib1.set(GregorianCalendar.MONTH,GregorianCalendar.SEPTEMBER); //9 means october
		lib1.set(GregorianCalendar.DATE,24);
		lib1.set(GregorianCalendar.YEAR,year);
		lib2.set(GregorianCalendar.MONTH,GregorianCalendar.OCTOBER); //9 means october
		lib2.set(GregorianCalendar.DATE,23);
		lib2.set(GregorianCalendar.YEAR,year);
		
		sag1.set(GregorianCalendar.MONTH,GregorianCalendar.NOVEMBER); //9 means october
		sag1.set(GregorianCalendar.DATE,23);
		sag1.set(GregorianCalendar.YEAR,year);
		sag2.set(GregorianCalendar.MONTH,GregorianCalendar.DECEMBER); //9 means october
		sag2.set(GregorianCalendar.DATE,22);
		sag2.set(GregorianCalendar.YEAR,year);
		
		cap1.set(GregorianCalendar.MONTH,GregorianCalendar.DECEMBER); //9 means october
		cap1.set(GregorianCalendar.DATE,23);
		cap1.set(GregorianCalendar.YEAR,year);
		cap2.set(GregorianCalendar.MONTH,GregorianCalendar.JANUARY); //9 means october
		cap2.set(GregorianCalendar.DATE,20);
		cap2.set(GregorianCalendar.YEAR,year);
	}
	
	public static void main(String[] args)throws IOException {
		//BufferedReader k = new BufferedReader(new FileReader("D:/uva-input.txt.txt"));
		BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter z = new PrintWriter(System.out);	
		int T = Integer.valueOf(k.readLine());
		int test = 1;
		while(T-->0){
			GregorianCalendar g = new GregorianCalendar();
			String s = k.readLine();
			int monn = Integer.valueOf(s.substring(0,2));monn--;
			int datee = Integer.valueOf(s.substring(2,4));
			int yearr = Integer.valueOf(s.substring(4,8));
			set(yearr);
			g.set(GregorianCalendar.MONTH,monn);
			g.set(GregorianCalendar.DATE,datee);
			g.set(GregorianCalendar.YEAR,yearr);
			g.add(GregorianCalendar.DATE,(40*7));
			
			int mon = g.get(GregorianCalendar.MONTH);
			mon++;
			int date = g.get(GregorianCalendar.DATE);
			int year = g.get(GregorianCalendar.YEAR);
			if(g.compareTo(ver1)>=0 && g.compareTo(ver2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" virgo");
			else if(g.compareTo(aq1)>=0 && g.compareTo(aq2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" aquarius");
			else if(g.compareTo(pi1)>=0 && g.compareTo(pi2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" pisces");
			else if(g.compareTo(ari1)>=0 && g.compareTo(ari2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" aries");
			else if(g.compareTo(ta1)>=0 && g.compareTo(ta2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" taurus");
			else if(g.compareTo(ge1)>=0 && g.compareTo(ge2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" gemini");
			else if(g.compareTo(can1)>=0 && g.compareTo(can2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" cancer");
			else if(g.compareTo(le1)>=0 && g.compareTo(le2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" leo");
			else if(g.compareTo(Scor1)>=0 && g.compareTo(Scor2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" scorpio");
			else if(g.compareTo(lib1)>=0 && g.compareTo(lib2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" libra");
			else if(g.compareTo(sag1)>=0 && g.compareTo(sag2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" sagittarius");
			else if(g.compareTo(cap1)>=0 && g.compareTo(cap2)<=0) z.println((test++)+" "+mon+"/"+date+"/"+year+" capricorn");
				
			}
		z.flush();
		}
	}

Re: 11947 - Cancer or Scorpio

Posted: Thu Nov 14, 2013 10:53 pm
by brianfry713
Try input:

Code: Select all

2
03272012
03262012

Re: 11947 - Cancer or Scorpio

Posted: Fri Apr 25, 2014 12:41 pm
by uDebug
Here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

12
01042009
02201987
03261776
04229200
05221999
06191887
07211654
08222222
09203001
10214567
11292160
02011914
AC Output:

Code: Select all

1 10/11/2009 libra
2 11/27/1987 sagittarius
3 12/31/1776 capricorn
4 01/27/9201 aquarius
5 02/26/2000 pisces
6 03/25/1888 aries
7 04/27/1655 taurus
8 05/29/2223 gemini
9 06/27/3002 cancer
10 07/27/4568 leo
11 09/05/2161 virgo
12 11/08/1914 scorpio

11947 Cancer or Scorpio Runtime Error.

Posted: Fri May 16, 2014 12:39 am
by mratan16
I keep getting a runtime error on this problem. Can't figure out why.

Below is the code. Any help is appreciated

Code: Select all

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>


using namespace std;

double toInt(string &a)
{
	double ret=0;
	for(int i=0; i<a.size(); ++i)
	{
		ret+=a[i]-'0';
		ret*=10;
	}
	ret/=10;
	return ret; 
}

bool isLeap(int year)
{
	if(year%4==0 && year%100!=0)
	{
		return true;
	}
	else if(year%100==0 && year%400==0)
	{
		return true;
	}
	else 
	{
		return false; 
	}
}

int month_length[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

pair <int,int> signs[13];



string sign_name[]={"aquarius","pisces", "aries", "taurus","gemini", "cancer", "leo","virgo", "libra",
					"scorpio","sagittarius","capricorn"};


int findsign(int m, int d)
{
	int ret;
	ret=m-1;
	if(d<=signs[ret].second){ret--;}
	return ret; 
}

int main()
{
	signs[0]= make_pair (1,21);
	signs[1] = make_pair (2,20);
	signs[2] = make_pair (3,21); 
	signs[3] = make_pair (4,21);
	signs[4] = make_pair (5,22); 
	signs[5] = make_pair (6,22);
	signs[6] = make_pair (7,23);
	signs[7] = make_pair (8,22);
	signs[8] = make_pair (9,24);
	signs[9] = make_pair (10,24);
	signs[10] = make_pair (11,23);
	signs[11] = make_pair (12,23);
	signs[12] = make_pair (1,20);

	int runs,temp,m,d,y,move;
	string input;

	cin >> runs; 

	for(int i=0; i<runs; ++i)
	{
		cin >> input;

		string month=input.substr(0,2);
		string day= input.substr(2,2);
		string year= input.substr(4);

		 m=toInt(month);
		 d=toInt(day);
		 y=toInt(year);


		 move=0;

		while(move<280)
		{
			if(isLeap(y))
			{
				month_length[2]++;
			}

			if(280-move>month_length[m])
			{

				move+= month_length[m]-d; 
				d=0; 
				if(m==12) {m=1; y++;}
				else {m++;}
			}
			else
			{
				d+=280-move;
				cout << i+1 << " ";

				
				 temp= findsign(m,d);
			
				if(m<10){cout << "0" << m << "/";}
				else{cout << m << "/";}

				if(d<10){cout << "0" << d << "/";}
				else{cout << d << "/";}

				cout << y << " ";

				cout << sign_name[temp]; 
				cout << endl;
				

				break;
			}


			if(month_length[2]!=28){month_length[2]--;}
			
		}

	}
	return 0; 
}


Re: 11947 Cancer or Scorpio Runtime Error.

Posted: Fri May 16, 2014 11:47 pm
by brianfry713
Try solving it without using floating point.

Re: 11947 Cancer or Scorpio Runtime Error.

Posted: Sun May 18, 2014 5:05 am
by mratan16
Still not accepted unfortunately. Still a runtime error. Any other ideas?