0

WHAT IS THIS????

#include <iostream> #include <fstream> #include <cmath> using namespace std; ifstream in("max.in"); int n, nr, cnr, i, j, u, uc, max1 = 0, max2, ss[3500];// sir schimbat int main() { in >> n; for (i = 0; i < n; i++) { in >> nr; cnr = nr; max2 = nr; u = -1; // 43, 32, 9, 43, 21, 76, 211, 97, 321. while (cnr > 0) { cnr /= 10; u++; } cout << nr << '\n'; for (j = 0; j < u; j++) { uc = nr % 10; nr = nr / 10; nr = nr + pow (10, u) * (uc == 0 ? 1 : uc); if (max2 < nr) max2 = nr; cout << nr << '\n'; } if (max1 < max2) max1 = max2; ss[i] = max2; cout << "max1:"<< max1; } } // Could you please test this out on your machine and put these numbers (9 34 23 9 43 21 67 121 79 213) in "max.in" ? // You'll also have to create the "max.in" file oviously // This program is supposed to try all different combinations of the digits of the numbers within a set taken one by one while keeping record of the biggest number that was met which is max1 // I'm having very weird bugs, help me! // max1 is supposed to be 321

22nd May 2018, 8:31 PM
XOPGAMINGX _300
XOPGAMINGX _300 - avatar
3 odpowiedzi
0
You (and we) could test here easily enough by writing your input file first. int main() { string heredoc = R"(9 34 23 9 43 21 67 121 79 213)"; ofstream out("max.in"); out << heredoc; out.close(); // Then just move your "in" stream to the next line: ifstream in("max.in"); Now your code runs here with an input file.
22nd May 2018, 9:49 PM
Kirk Schafer
Kirk Schafer - avatar
0
now I've seen that for some reason it doesn't work right on my pc but it works in the sololearn playground, weird isn't it?
23rd May 2018, 4:58 AM
XOPGAMINGX _300
XOPGAMINGX _300 - avatar
0
Maybe a version difference? https://code.sololearn.com/cu8tmoP4h80H/?ref=app Hopefully someone can help more (I have to sign off soon).
23rd May 2018, 5:21 AM
Kirk Schafer
Kirk Schafer - avatar