#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
// cout << "Hello world!" << endl;
int t,i,j,a,flag;
char str[1000001];
cin>>t;
while(t--)
{
a=1;
scanf("%s",str);
for(i=0;i<=strlen(str);i++)
{flag=0;
if(!isdigit(str[i]))
{flag=0;
for(j=i-1;isdigit(str[j]);j--)
{
if(str[j]!='0')
{
flag++;
a*=str[j]-'0';
//cout<<"flag"<<flag<<" "<<a<<"A"<<endl;
break;
}
}
if(flag==0)
{
a=0;break;
}
}
while(a>9)
{
if((a%10)!=0)
{
a=a%10;
//cout<<"a"<<a<<endl;
}
else
{
a=a/10;
}
}
}
if(a)
printf("%d\n",a);
else
printf("Robot hanged.\n");
}
return 0;
}
This is the code for the following problem link.
I am getting a wrong answer despite my code working for all the test cases.
Can anyone tell me for which test case my code is not working.
A robot named as Maestro, works on right most digit of number. For eg. 123456 is a number. Maestro would work with 6. But now, if number is 12345600. It will work with 6.
Input Specification
Input a variable t which is the number of test cases. Then input a string having alternate integers and multiplication characters. Your job is to calculate the last non zero digit in that mathematical expression. Number can be as large as 10^19. 0 < t<100
Output Specification
Output consists of a single number which is the last non zero digit of the value of the expression. If the expression evaluates to be zero, output should be “Robot hanged.”
Example
Sample Input:
2
2X3X7X5
2X0X4X25
Sample Output:
1
Robot hanged.