NATIONAL LIBRARY
Problem Description
The National Library in the state of Laos is to be elaborately renovated owing to its 100 th year anniversary celebrations. It is one of the oldest libraries in the state and has been a symbol of legacy.
The Library management wanted to rebuild the steel bookracks in the building and renumber them thereafter.
Each of the n racks should be assigned with a number from 1 to n. It is very obvious that each rack should be assigned distinct numbers.
Mark, a craftsman was assigned the task of renumbering the racks with his artistic carving.
He normally charges wages based on the number of carvings he does. While numbering the racks, he treats each carving of the digit in the numbers of the racks for wages. Hence he wanted to keep a note of how many such digits he is carvings.
For example,
If n = 13, the racks get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 carvings.
Input Format:
The first line contains integer n, which corresponds to the number of bookracks in the library.
Output Format:
Print the number of carvings that Mark does to number all the bookracks.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output.]
CODING ARENA
#include <stdio.h>
int main()
{
int a,i,count=0;
scanf("%d",&a);
if(a>0)
{
for(i=1;i<=a;i++)
{
count+=1;
if(i>9 && i<100)
count+=1;
else if(i>99 && i<1000)
count+=2;
}
}
printf("%d",count);
return 0;
}
Test Case 1
Input (stdin)13
Expected Output
17
Test Case 2
Input (stdin)0
Expected Output
0
No comments:
Post a Comment