Omek-05's blog

By Omek-05, history, 6 weeks ago, In English

hi all, i am new to both programming and this website. My query is that sometimes even though my code works correctly in my compiler but it won't even pass through the first test here in codeforces. Is there something i can do about it ? For example in this (problem) , can anyone check my code

#include<stdio.h>
int power(int a, int n)
{
    int i,sum;
    sum = 1;
    for(i=1;i<=n;i++)
    {
        sum = sum*a;
    }
    return sum;
}
int count(int n)
{
    int i,pro;
    while(n!=0)
   {
       n=n/10;
       pro++;
   }
   return pro;
}
int main()
{
    int t,j,i,Count,Digit,o;
    long long int n;
    scanf("%d",&t);
    for(j=0;j<t;j++){
    scanf("%lld",&n);
    Count = count(n);
    Digit = 1;
    for(i=1;i<Count;i++)
    {
       Digit = Digit + power(10,i);
    }
    if(n < Digit)
    {
        o = (Count -1)*9;
        printf("%d\n",o);
    }
    else if(n == 9*Digit)
    {
        o = (Count)*9;
        printf("%d\n",o);
    }
    else
    {
        for(i=2;i<10;i++)
        {
            if(n < i*Digit)
            {
                o = (Count -1)*9 + (i-1);
                printf("%d\n",o);
                break;
            }
        }
    }
    }
    return 0;
}
 
 
 
 
  • Vote: I like it
  • -19
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it -12 Vote: I do not like it

There is thing called sample cases.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Omek-05 (previous revision, new revision, compare).

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Omek-05 (previous revision, new revision, compare).