UVa 11947 - Cancer or Scorpio

11947 - Cancer or Scorpio

 * http://uva.onlinejudge.org/external/119/11947.html

Summary
Given a date, add 40*7 days to the date, print the zodiac of the new date. The zodiacs are given as a date range.

Explanation
Use Java's Calendar to create the date and advance 40*7 days. Use Java's GregorianCalendar to create date range for the zodiacs. It's only a matter of checking whether the date is between a certain range.

Gotchas

 * Java's Calendar using month from index 0, while the date is from index 1.
 * Be careful for Capricorn's zodiac, its date range wraps around the year.

Input
2 01232009 01232008

Output
1 10/30/2009 scorpio 2 10/29/2008 scorpio

Categories here, use the form, see Categories for a list

using namespace std; bool Bisiesto(int years){return years % 4 == 0 && !(years % 100 == 0 && years % 400 != 0);} int dayss (int m, int y) { if (m == 11 || m == 4 || m == 6 || m == 9) return 30;
 * 1) include
 * 2) include 
 * 3) include 
 * 4) define FOR(i,a,b) for(int i=(a);i<(b);i++)

if (m == 2) return 28 + Bisiesto (y);

return 31; }

int main { int j,t, i, months, day, years, days; char date[10]; scanf("%d", &t); FOR(i,0,t) {    scanf("%2d%2d%4d", &months, &day, &years); for (int j = 0; j < 40; ++j) { int c = dayss(months, years); day = (day + 6) % c + 1; if (day < 8) { months = months % 12 + 1; if (months == 1) ++years; }     }	  printf ("%d %02d/%02d/%04d ", i+1, months, day, years % 10000);;

if ((day>=21 && months==1) || (day<=19 && months==2)) printf("aquariusn"); if ((day>=20 && months==2) || (day<=20 && months==3)) printf( "piscesn"); if ((day>=21 && months==3) || (day<=20 && months==4)) printf( "ariesn"); if ((day>=21 && months==4) || (day<=21 && months==5)) printf( "taurusn"); if ((day>=22 && months==5) || (day<=21 && months==6)) printf( "geminin"); if ((day>=22 && months==6) || (day<=22 && months==7)) printf( "cancern"); if ((day>=23 && months==7) || (day<=21 && months==8)) printf( "leon"); if ((day>=22 && months==8) || (day<=23 && months==9)) printf( "virgon"); if ((day>=24 && months==9) || (day<=23 && months==10)) printf( "libran"); if ((day>=24 && months==10) || (day<=22 && months==11)) printf( "scorpion"); if ((day>=23 && months==11) || (day<=22 && months==12)) printf( "sagittariusn"); if ((day>=23 && months==12) || (day<=20 && months==1)) printf( "capricornn"); } }