11947 - Cancer or Scorpio

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

Moderator: Board moderators

sijan
New poster
Posts: 5
Joined: Fri Sep 09, 2011 6:44 pm

11947 - Cancer or Scorpio

Post 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]
Last edited by sijan on Fri Sep 09, 2011 11:41 pm, edited 1 time in total.
sijan
New poster
Posts: 5
Joined: Fri Sep 09, 2011 6:44 pm

Re: 11947 - Cancer or Scorpio

Post by sijan »

I got ac...:D
shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Problem with the problem "Cancer or Scorpio"

Post 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?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Problem with the problem "Cancer or Scorpio"

Post by brianfry713 »

Next time post the problem number 11947.
Code all the zodiac signs.
Check input and AC output for thousands of problems on uDebug!
ok_woei
New poster
Posts: 2
Joined: Thu Jan 31, 2013 6:38 pm

11947 - Cancer or Scorpio

Post 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
Last edited by ok_woei on Thu Feb 14, 2013 7:16 am, edited 1 time in total.
lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 11947 - Cancer or Scorpio

Post 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.
ok_woei
New poster
Posts: 2
Joined: Thu Jan 31, 2013 6:38 pm

Re: 11947 - Cancer or Scorpio

Post by ok_woei »

Thx.. that was the worst mistake!!
justadreamer
New poster
Posts: 2
Joined: Sat Apr 27, 2013 12:43 am

Re: 11947 - Cancer or Scorpio

Post 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);
		}
	}
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11947 - Cancer or Scorpio

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Wrong Answer: 11947 - Cancer or Scorpio

Post 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();
		}
	}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11947 - Cancer or Scorpio

Post by brianfry713 »

Try input:

Code: Select all

2
03272012
03262012
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11947 - Cancer or Scorpio

Post 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
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
mratan16
New poster
Posts: 21
Joined: Fri May 16, 2014 12:36 am

11947 Cancer or Scorpio Runtime Error.

Post 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; 
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11947 Cancer or Scorpio Runtime Error.

Post by brianfry713 »

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
mratan16
New poster
Posts: 21
Joined: Fri May 16, 2014 12:36 am

Re: 11947 Cancer or Scorpio Runtime Error.

Post by mratan16 »

Still not accepted unfortunately. Still a runtime error. Any other ideas?
Post Reply

Return to “Volume 119 (11900-11999)”