#include <iostream>
#include <fstream>
usingnamespace std;
int subset[10];
// function checks whether the given integer is from subset or not
bool is_from_subset(int x)
{
//x is maximum 4 digit long
for(int j=1000; j>0; j/=10){
if(x>j){
if( x/j%10 == 0) return 0; //removing zeros
if( ((x/j)%10)!=subset[((x/j)%10)]) return 0;
}
}
returntrue;
}
main()
{
ifstream fin("crypt1.in");
ofstream fout("crypt1.out");
int N, d, i=0;
fin>>N;
for(i=0; i<10; i++) subset[i]=0;
i=0;
while(i<N){fin>>d; subset[d]=d; i++;}
if(is_from_subset(22*222)) cout<<"22*222";
getchar();
}
the problem is here:
if(is_from_subset(22*222)) cout<<"22*222";
it does not produce an output but when I do the following:
1 2
int num=22*222;
if(is_from_subset(num)) cout<<"22*222";
Output:
4884
which is correct output.
I do not understand why when the argument of the function is_from_subset() is integer the output is correct, but when the argument of the function is any expression there is no output???
Please, can anyone explain me my mistake???
int num=22*222;
if(is_from_subset(num)) cout<<"22*222";
Erm, this won't output 4884, it will output 22*222 which signals you aren't showing us something.
In your main function, you assign integer i to 0 twice which is pointless. You also use a while statement where a for statement would be much more appropriate. The integer N is also input into a file with junk. Your subset function also uses return statements of 0 which is the same as returning true in this case. I don't think this is the functionality you wanted.