Epic Systems Interview Question
Software Engineer / Developersand wat would be a good option...am sure we have to manipulate only the month not the whole date...that would be mad....
Its foolish to assume only 2000+
// assuming the dates are from 1910 to 2009.
int m,d,y;
Cout<<"Enter the year";
cin>>y;
if(y<0 || y > 99)
cout<<"Invalid year. It has to be between 0 and 99";
boolean leapyear = (y%4==0 && y%100 != 0)?true:false;
cout<<"Enter the Month"<<endl;
cin>>m;
if(m<1 || m > 12)
cout<<"Invalid Month. It has to be between 1 and 12";
Cout<<"Enter the date";
cin>>d;
if(d<1 || d > 31)
cout<<"Invalid date. It has to be between 1 and 31";
if(d>28 && m==2 && !leapyear || d>29 && m ==2 && leapyear)
cout<<"There can't be more than 28 days in february or more than 29 days in february when it is a leapyear";
String a[]={"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
};
String b[]={"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"ninteen",
};
String c[]={
"twenty",
"thirty",
"fourty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninty"
};
String d[]={
"first",
"second",
"third",
"fourth",
"fifth",
"sixth",
"seventh",
"eighth",
"nineth",
};
int first = year/10;
int second = year%10;
char date;
char month;
char year;
case(d)
{
d=1: cout<<d[0];
break;
d=2: cout<<d[1];
break;
d=3: cout<<d[2];
break;
d=4: cout<<d[3];
break;
d=5: cout<<d[4];
break;
d=6: cout<<d[5];
break;
d=7: cout<<d[6];
break;
d=8: cout<<d[7];
break;
d=9: cout<<d[8];
break;
d=10: cout<<b[0]<<"th";
break;
d=11: cout<<b[1]<<"th";
break;
d=12: cout<<"twelfth";
break;
d=13: cout<<b[3]<<"th";
break;
d=14: cout<<b[4]<<"th";
break;
d=15: cout<<b[5]<<"th";
break;
d=16: cout<<b[6]<<"th";
break;
d=17: cout<<b[7]<<"th";
break;
d=18: cout<<b[8]<<"th";
break;
d=19: cout<<b[9]<<"th";
break;
d=20: cout<<c[0]<<"th";
break;
d=30: cout<< "Thirteeth";
break;
d=31: cout<<"Thirty First";
break;
}
if(20<d<30)
{
int f= d%20;
cout<<"Twenty";
case(f)
{
case 1:
cout<<d[0];
break;
case 2:
cout<<d[1];
break;
case 3:
cout<<d[2];
break;
case 4:
cout<<d[3];
break;
case 5:
cout<<d[4];
break;
case 6:
cout<<d[5];
break;
case 7:
cout<<d[6];
break;
case 8:
cout<<d[7];
break;
case 9:
cout<<d[8];
break;
}
}
case(m)
{
m=1:
cout<<" of January";
break;
m=2:
cout<<"of February";
break;
m=3:
cout<<"of March";
break;
m=4:
cout<<"of April";
break;
m=5:
cout<<"of May";
break;
m=6:
cout<<"of June";
break;
m=7:
cout<<"of July";
break;
m=8:
cout<<"of August";
break;
m=9:
cout<<"of September";
break;
m=10:
cout<<"of October";
break;
m=11:
cout<<"of November";
break;
m=12:
cout<<of December;
break;
}
if(year/10 >= 1)
{
cout<<"Nineteen Hundred and";
switch (first)
{
case 1:
cout<<"";
switch(second)
{
case 0:
{
cout<<b[0]<<endl;
break;
}
case 1:
{
cout<<b[1]<<endl;
break;
}
case 2:
{
cout<<b[2]<<endl;
break;
}
case 3:
{
cout<<b[3]<<endl;
break;
}
case 4:
{
cout<<b[4]<<endl;
break;
}
case 5:
{
cout<<b[5]<<endl;
break;
}
case 6:
{
cout<<b[6]<<endl;
break;
}
case 7:
{
cout<<b[7]<<endl;
break;
}
case 8:
{
cout<<b[8]<<endl;
break;
}
case 9:
{
cout<<b[9]<<endl;
break;
}
}}
case 2
{
cout<<c[0];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 3
{
cout<<c[1];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 4
{
cout<<c[3];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 5
{
cout<<c[4];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 6
{
cout<<c[5];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 7
{
cout<<c[6];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 8
{
cout<<c[7];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
case 9
{
cout<<c[8];
switch(second)
{
case 0:
{
cout<<a[0]<<endl;
break;
}
case 1:
{
cout<<a[1]<<endl;
break;
}
case 2:
{
cout<<a[2]<<endl;
break;
}
case 3:
{
cout<<a[3]<<endl;
break;
}
case 4:
{
cout<<a[4]<<endl;
break;
}
case 5:
{
cout<<a[5]<<endl;
break;
}
case 6:
{
cout<<a[6]<<endl;
break;
}
case 7:
{
cout<<a[7]<<endl;
break;
}
case 8:
{
cout<<a[8]<<endl;
break;
}
case 9:
{
cout<<a[9]<<endl;
break;
}
}}
}
else
{
cout<<"Two Thousand ";
switch(second)
{
case 0:
cout<<a[0];
break;
case 1:
cout<<a[1];
break;
case 2:
cout<<a[2];
break;
case 3:
cout<<a[3];
break;
case 4:
cout<<a[4];
break;
case 5:
cout<<a[5];
break;
case 6:
cout<<a[6];
break;
case 7:
cout<<a[7];
break;
case 8:
cout<<a[8];
break;
case 9:
cout<<a[9];
break;
}
}
}
import java.util.Scanner;
public class DateConverter {
public static void main(String agrs[])
{
Scanner sc = new Scanner(System.in);
int date = sc.nextInt();
System.out.println(getDate(date));
}
static String getDate(int d)
{
String[] arr = {"Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"};
int year = d%100;
d/=100;
int month = d%100;
d/=100;
int date = d%100;
if(year>=00 && year<=15)
year=2000+year;
else
year = 1900+year;
return (date+" "+arr[month-1]+" "+year);
}
}
I have used the fact that if year is between 00-15 then it is 2000 else we are talking about the 1900.
any example ?
- romeo August 27, 2009