Code works on my comp. not on CodeChef

I was Solving the first question of this month’s Cookoff.

Given Number ‘N’ find next no. having three 3’s in it. I used itoa function in my solution and it compiled and ran perfectly on my CodeBlocks IDE.

But when I submitted it through Codechef C++ 14 it gave compile error.

Please Help? What is wrong here?

The Error :-

prog.cpp: In function ‘int main()’:
prog.cpp:25:25: error: ‘itoa’ was not declared in this scope
         itoa(n,buffer,10);

My code:-

#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<string>

#include<string.h>
#define ll long long int
#define li long int

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    ll t;
    cin>>t;


    while(t--)
    {
        char buffer [33];

        ll n;
        cin>>n;
        itoa(n,buffer,10);
        string str = string(buffer);
        ll len=str.size();
        if(n<333)
            cout<<"333\n";
        else
        {
            ll threes=0;
            for(ll i=0;i<len;i++)
            {
                if(str[i]=='3')
                {
                    threes++;
                }

            }
            if(threes>3)
                    {cout<<n+1<<'\n';continue;}

            else{
                    ll f=true;
                ll dig=n+1;
                while(f)
                {
                    char buffer2 [33];
                    itoa(dig,buffer2,10);
                    string str2 = string(buffer2);
                    ll len2=str2.size();

                    ll threes2=0;
                    for(ll i=0;i<len2;i++)
                    {
                        if(str2[i]=='3')
                        {
                            threes2++;
                        }

                    }
                    if(threes2 >=3){
                        f=false;
                    }
                    else
                    {
                        dig++;
                    }
                }
                cout<<dig<<'\n';

            }

        }

    }
    return 0;
}

Probably you are using Windows. itao is available in MinGW gcc which your Codeblock ide might be using for compiling codes. Codechef probably is not using MinGW gcc. Try using to_string instead.

1 Like