Omek-05's blog

By Omek-05, history, 3 years 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

| Write comment?