Help me! (Newbie)

Revision en3, by Omek-05, 2021-05-14 21:50:28

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;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Omek-05 2021-05-14 21:50:28 20
en2 English Omek-05 2021-05-14 21:49:10 1072 Tiny change: 'k my code #include<s' -> 'k my code \n\n#include<s'
en1 English Omek-05 2021-05-14 21:42:31 254 Initial revision (published)