Anonymous Anonymous - 1 month ago
106 0

No description

C++

asdadasd

#include<stdio.h>
#include<stdlib.h>

int toInt(char s[]) {
int i, n = 0;
for (i = 0; s[i] != '\0'; i++) {
n = n * 10 + s[i] - '0';
}
return n;
}
int evaluate(char s[],int i)
{
   int j,k,ret=0,l=0;
   char t,temp[3];
   for(j=65;j<=73;j++)
   {
       t=j;
       for(k=0;k<11;k++)
           if(s[k]==t)
           {
           s[k]=l;
           l=((48-(65-k))%(48+i));
           }
   }
   temp[0]=s[0];
   temp[1]=s[1];
   temp[2]=s[2];
   i = toInt(temp);
  
   temp[0]=s[4];
   temp[1]=s[5];
   temp[2]=s[6];
   j = toInt(temp);
   temp[0]=s[8];
   temp[1]=s[9];
   temp[2]=s[10];
   k = toInt(temp);
   if((i+j)==k)
   {
       printf("%s\n",s);
       ret=1;
   }
   return ret;      
      
}
int main()
{
   char s[100];
   int i;

   while(1)
   {
       printf("\nEnter the formula: ");
       scanf("%s",s);
       if(s[0]=='-' && s[1]=='1')
           break;
       for(i=0;i<=9;i++)
       {
           if(evaluate(s,i)==1)
               i=11;
       }
       if(i==10)
       printf("\nNo Solution!");
    }

	return 0;
}