How can i fullfill constraints within same logic

/* Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

Input Format
The first line contains a single integer x (1 ≤ x ≤ 10^18) — the number that Luke Skywalker gave to Chewbacca.

Constraints
x <= 100000000000000000

Output Format
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

Sample Input
4545
Sample Output
4444
Explanation
There are many numbers form after inverting the digit. For minimum number, check if inverting digit is less than or greater than the original digit. If it is less, then invert it otherwise leave it.
 */
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    
   char a[100000000000000000];
 cin.getline(a,100); 
  int flag=0;
for (int i = 0; i < strlen(a); i++)
 {
   int x= a[i]-'0';
   if (9-x<=x)
   {
       a[i]=(9-x)+'0';
       flag=1;
   }
    } 
    for (int i = 0; i <strlen(a); i++)
    {   if (a[i]!='0')
    {   flag=0;
        cout<<a[i];
    }
    else
    {
        if (flag==0)
        {
            cout<<a[i];
        }
        
    }
    
    }

    return 0;
}

You must use long long data type for this question.
Check this https://ide.codingblocks.com/s/268403

can we use long long dat type modifier with char?

i have not reached vectors till now in the course

So you can use an array inplace of vector.

if i will use int type array then how will i access each i th digit as in online input file it will consider 4545 as single input element

One approach is by storing each digit in the integer array and then performing the operations.
Also you can take the input in the form of string and then proceed. Choose whichever way you want to do

if i use string data type constraints will fullfill?

on using string data dtype testcase 2 and 4 still fails

Yes…x can be upto 10^18…means maximum 18 digits…

Save your code on ide.codingblocks.com and share its link.

also please tell what is the maximum length of string we can store in a string type array

I checked your code with input:
9999

EXPECTED O/P is:
9000

But your code is not giving any output for this case.
Dry run and check with it.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.