C++ Help (Integer Pattern) -
the question :
if sequence of digits in x forms substring of sequence of digits in y, outputs "x substring of y"; otherwise, if sequence of digits in x forms subsequence of sequence of digits in y, outputs "x subsequence of y"; otherwise, outputs "x neither substring nor subsequence of y".
do not use arrays or strings in program
the output should follows
enter y : 239847239
enter x : 847
x substring of y
enter y : 239847239
enter x : 3923
x subsequence of y
enter y : 239847239
enter x : 489
x neither substring nor subsequence of y
and below got far... (haven't coded subsequence clueless)
i know coding unefficient , suitble use above model output. improvements or comments how fix appreciated.
#include <cmath> #include <iostream> using namespace std; int main() { cout << "enter y: " ; int y; cin >> y; cout << "enter x: "; int x; cin >> x; if (y >= x){ // below possibilities of substrings 9 decimal places. if( x == (y % 10)) cout << "x substring of y"; else if (x == (y % 100)) cout << "x substring of y"; else if (x == (y % 1000)) cout << "x substring of y"; else if (x == (y % 10000)) cout << "x substring of y"; else if (x == (y % 100000)) cout << "x substring of y"; else if (x == (y % 1000000)) cout << "x substring of y"; else if (x == (y % 10000000)) cout << "x substring of y"; else if (x == (y % 100000000)) cout << "x substring of y"; else if (x == (y % 1000000000)) cout << "x substring of y"; else cout << "x neither substring nor subsequence of y"; } else cout << "neither subsequence nor subset"; // prints out when y less x. return 0;
}
Comments
Post a Comment