Beispiel #1
0
void validate(char *str1, char *str2, char *str,int ar1[],int ar2[]){
    
    int num1 = arrayToNumber(ar1, strlen(str1));
    int num2 = arrayToNumber(ar2, strlen(str2));
    int res = num1 + num2;
    int ar[strlen(str)];
    int index1, index2;
    int p;
//    printf("%d + %d = %d\n",num1,num2,res);
    if(numberOfDigits(res) == strlen(str)){
    numberToArray(ar, res);
        if(checkFinalString(str, ar)){
            for(int i=0;i<strlen(str);i++){
                index1 = isExist(str1,str[i]);
                index2 = isExist(str2,str[i]);
//        printf("str1: %s str2: %s ch: %c\n",str1, str2, str[i]);
//        printf("index1: %d index2: %d index: %d\n",index1, index2, index);
                if (index1!=-1) {
                    if (ar1[index1] != ar[i]) {
                        return;
                    }
                }
                else{
                    for (p=0; p<strlen(str1); p++) {
                        if (ar1[p] == ar[i]) {
                            return;
                        }
                    }
                }
                if (index2!=-1) {
                    if (ar2[index1] != ar[i]) {
                        return;
                    }
                }
                else{
                    for (p=0; p<strlen(str2); p++) {
                        if (ar2[p] == ar[i]) {
                            return;
                        }
                    }
                }
            }
            totalRes++;
            printf("%d + %d = %d \t",num1,num2, res);
            if (totalRes%2==0) {
                printf("\n");
            }
        }
    }
}
Beispiel #2
0
bool assign(int num[],int index,int sol[],int *l,int len){
    int temp=0,k=0,i;
    for (i=0; i<10; i++) {
        num[index] = i;
        sol[(*l)++] = arrayToNumber(num,len);
        if(allNine(num,len)){
            return true;
        }
    }
    return false;
}
Beispiel #3
0
Real64 JSON::as_real() const
{
	switch (m_type)
	{
	case e_null: return 0;
	case e_bool: return (m_bool ? 1 : 0);
	case e_integer: return Real64(m_integer);
	case e_real: return m_real;
	case e_string: return stringToNumber(m_string).as_real();
	case e_array: return arrayToNumber(m_array).as_real();
	case e_object: return objectToNumber(m_object).as_real();
	}
	return 0;
}
Beispiel #4
0
bool JSON::as_bool() const
{
	switch (m_type)
	{
	case e_null: return false;
	case e_bool: return m_bool;
	case e_integer: return as_integer() != 0;
	case e_real: return as_real() != Real64(0);
	case e_string: return stringToNumber(m_string).as_bool();
	case e_array: return arrayToNumber(m_array).as_bool();
	case e_object: return objectToNumber(m_object).as_bool();
	}
	return 0;
}
Beispiel #5
0
bool checkFinalString(char *str,int ar[]){
    bool flag = true;
    int index=-1, i;
    if (totalNumberOfMatchingCharacter(str) == totalNumberOfMatchingNumbers(arrayToNumber(ar, strlen(str))) ) {
        flag = true;
        for (i=0; i<strlen(str); i++) {
            index = isExist(str, str[i]);
            if (index != i) {
                if (ar[i] != ar[index]) {
                    flag = false;
                }
            }
        }
        
    }
    else{
        flag = false;
    }
    return flag;
}