Page 5 of 6

I can just give a tips.

Posted: Mon Aug 28, 2006 3:22 am
You can use a kind of technic that store your humble numbers in memory. That means precalculate the humble numbers(it's just total 5842).

I hope it helps you.

ps. anyway, your answer printing is wrong. you have to consider about the numbers like 11th, 12th, 13th, 111th, ... and so on.

443 WA

Posted: Tue Nov 07, 2006 8:39 am
#include <stdio.h>

int main() {
int i, j, num;
long temp;
long humble[5483];
char suffix[2];
suffix[0] = 't';
suffix[1] = 'h';
humble[0] = 1;

for(i = 1; i < 5483; i++)
{
humble[i] = 2100000000;

for(j = 0; j < i; j++)
{
if(humble[j] * 2 > humble[i - 1])
{
if(humble[j] * 2 < humble[i])
{
humble[i] = humble[j] * 2;
}
}
else if(humble[j] * 3 > humble[i - 1])
{
if(humble[j] * 3 < humble[i])
{
humble[i] = humble[j] * 3;
}
}
else if(humble[j] * 5 > humble[i - 1])
{
if(humble[j] * 5 < humble[i])
{
humble[i] = humble[j] * 5;
}
}
else if(humble[j] * 7 > humble[i - 1])
{
if(humble[j] * 7 < humble[i])
{
humble[i] = humble[j] * 7;
}
}
}
}

scanf("%d", &num);

while( num!=0)
{
if( num%10 == 1 && num%100== 11) { suffix[0] = 's'; suffix[1] = 't';}
else if( num%10 == 2 && num%100 == 12) { suffix[0] = 'n'; suffix[1] = 'd';}
else if( num%10 == 3 && num%100 == 13) { suffix[0] = 'r'; suffix[1] = 'd';}
else {suffix[0]='t';suffix[1]='h';}
temp = humble[num - 1];

printf("The %d%s humble number is %ld.\n", num, suffix, humble[num-1]);
scanf("%d", &num);
}
return 0;
}

Posted: Tue Nov 07, 2006 8:40 am
can someone let me know whats wrong with this?

Posted: Tue Nov 07, 2006 10:41 am
May be the suffix chosing code is wrong.

Code: Select all

``````if ((i%100 - i%10) == 10)
suf = "th";
else
switch ( i%10 ) {
case 1: suf = "st"; break;
case 2: suf = "nd"; break;
case 3: suf = "rd"; break;
default: suf = "th"; break;
}
``````

Posted: Tue May 01, 2007 2:36 am
Somebody can compile my code

I compile (in Windows, with Bloodshed Dev-C++, and option -ansi -pedantic -Wall) and I dont find none warning or error.

Thanks

My code (CE)

Code: Select all

``````#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

...CODE REMOVE

if (n==11 || n==12 || n==13)
cout << "th";

...CODE REMOVE

``````
Thanks to "Jan" and "mf".

Posted: Tue May 01, 2007 3:09 am
I think you should include <algorithm> header to use min().

Posted: Tue May 01, 2007 11:48 am
Thanks.

But, now is WA.

I think the output is ok.

Please, somebodey can check me code.

Thanks.

Posted: Wed May 02, 2007 8:15 pm
If there are 1st, 2nd, 3rd, you can't say 1th, 2th...

Posted: Wed May 02, 2007 8:36 pm
My INPUT:

Code: Select all

``````1
2
3
4
11
12
13
21
22
23
100
1000
2500
5842
0``````

My OUTPUT:

Code: Select all

``````The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 2500th humble number is 20321280.
The 5842nd humble number is 2000000000.
``````
Where is the problem?

Posted: Wed May 02, 2007 9:13 pm
Ok, let me be more clear. What about 111, 512, ....

Posted: Wed May 02, 2007 9:25 pm
Thank you so much!

How can we do whitout you?

Thank you again.

443 Humble Numbers ....Getting a Wrong Answer...

Posted: Tue Jan 29, 2008 6:03 pm
Hi friends,
I seem to be getting a wrong answer....even though my code is workin for all the test cases i ever tried on it.....
Can somebody help me out n tell wat's the error..

here's the code

Posted: Wed Jan 30, 2008 10:14 am
You are not printing ordinals numbers in the right way. For instance, the correct output for 111 should be:
The 111th humble number is 576.
The 111st humble number is 576.
Got the idea?

Posted: Wed Jan 30, 2008 10:38 am
Thanx....
i got accepted now....
that line was intended to be
(p%100<=20 && p%100>=10)...
but i missed it out in the final code.....
thanx again for findin it out.....

why this code is not working???

Posted: Sun Nov 16, 2008 7:44 pm
i have done it as it is suggested
may be the array size is too large but i dont know what should be the size to store the humble number
and if there is a better idea of getting humble number using array pls give me that idea
my code is:

Code: Select all

``````#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

#define limit 5843
#define MAX 2000000000

long humblenum[MAX];

int main()
{
int n;
int i,j,k,l,pos=0;
for(i=0;i<limit;i++){
for(j=0;j<limit;j++){
for(k=0;k<limit;k++){
for(l=0;l<limit;l++){
humblenum[pos]=(pow(2,i))*(pow(3,j))*(pow(5,k))*(pow(7,l));
pos++;
}
}
}
}
sort(humblenum,humblenum+pos);
while(scanf("%d",&n)){
if(n==0)break;
if((n%100)/10==1)printf("The %dth humble number is %ld.\n",n,humblenum[n]);
else {
switch(n%10){
case 0:   case 4:   case 5:   case 6:   case 7:   case 8:   case 9:
printf("The %dth humble number is %ld.\n",n,humblenum[n]);
break;
case 1:
printf("The %dst humble number is %ld.\n",n,humblenum[n]);
break;
case 2:
printf("The %dnd humble number is %ld.\n",n,humblenum[n]);
break;
case 3:
printf("The %drd humble number is %ld.\n",n,humblenum[n]);
break;
}
}
}
return 0;
}

``````