+ 2
I need help with my cpp code
I solved this problem but when I submit it I received timeout/ SIGTERM errors. Please have a look at the code, Any optimization suggestions are welcome. Thank you! https://code.sololearn.com/cA23A12A9a21/?ref=app
2 Respostas
+ 2
You have a few issues with your temp variable use, anyways, this should work:
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int currentYear = 0;
int a, b, c, d, temp;
cin >> currentYear;
while (true)
{
currentYear++; //increment one year ahead
temp = currentYear;
a = currentYear % 10;//Storing the last digit of the year
temp /= 10; // removing the last digit of the year
b = temp % 10;
temp /= 10;
c = temp % 10;
temp /= 10;
d = temp;
if ((((a != b) && (a != c)) && ((a != d)) && ((b != c)) && ((b != d) && (c != d))))
{
//if year has distinct digits then print it out and break the loop
cout << currentYear;
break;
}
}
return 0;
}
+ 2
Aleksei Radchenkov
Thank you! I see my mistake now. reassign wasn't needed