C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

Project Euler Problem 17 – Number letter counts August 8, 2013

Filed under: Project Euler — whoami @ 19:56
Tags: ,

/* Warning: Donot try extracting answer from this and sumbit. This will not help you in Long Run */


/* Project Euler Problem 17 */
/*

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20
letters. The use of "and" when writing out numbers is in compliance with British usage.
*/

#include<stdio.h>
#include<string.h>

int main()
{

int i,j;
char str[100];

char str2[][100]={"one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred",
"thousand"};
int tot=0;


for(i=1;i<1000;i++)
{
//one digit number 1-9
if(i/10 == 0)
{
tot+=strlen(str2[i-1]);
printf("%s\n",str2[i-1]);

}
//two digit number 10-99
else if(i/100 == 0)
{
if(i>=10 && i<=19)
{
tot+=strlen(str2[i-1]);
printf("%s\n",str2[i-1]);
}
else if( i%10 == 0 )
{
tot+=strlen(str2[18+i/10-1]);
printf("%s\n",str2[18+i/10-1]);
}
else
{
int unit=i%10;
int tens=(i/10)%10;
tot=tot+strlen(str2[unit-1]) + strlen(str2[18+tens-1]);
printf("%s-%s\n",str2[18+tens-1], str2[unit-1]);
}

}
//three digit number 100-999
else if(i/1000 == 0)
{
tot+=strlen("hundred");
if(i%100 == 0)
{
tot= tot + strlen(str2[i/100-1]);
printf("%s hundred\n",str2[i/100-1] );
}
else if(i%10 == 0)
{
int hundredth=i/100;
int tens=((i/10)%10);
if(tens == 1)
{
tot=tot+strlen(str2[hundredth-1]) + strlen("ten")+strlen("and");
printf("%s hundred and ten\n",str2[hundredth-1]);

}
else
{
tot=tot+strlen(str2[hundredth-1])+strlen(str2[18+tens-1])+strlen("and");
printf("%s hundred and %s\n",str2[hundredth-1],str2[18+tens-1]);
}
}
else
{
int hundredth=i/100;
int tens=(i/10)%10;
int units=i%10;

tot=tot+strlen(str2[hundredth-1])+strlen("and");
printf("%s hundred and ", str2[hundredth-1]);
if(tens == 1)
{
tot=tot+strlen(str2[9+units]);
printf("%s\n",str2[9+units]);
}
else if(tens == 0)
{
tot=tot+strlen(str2[units-1]);
printf("%s\n",str2[units-1]);
}
else
{
tot=tot+strlen(str2[18+tens-1]) + strlen(str2[units-1]);
printf("%s-%s\n",str2[18+tens-1], str2[units-1]);
}
}
}
//sleep(1);
}

tot=tot+strlen("onethousand");
printf("one thousand\n");
printf("%d",tot);
return 0;
}