Problem J3: From 1987 to 2013
Problem Description
You might be surprised to know that 2013 is the first year since 1987 with distinct digits. The years
2014, 2015, 2016, 2017, 2018, 2019 each have distinct digits. 2012 does not have distinct digits,
since the digit 2 is repeated.
Given a year, what is the next year with distinct digits?
Input Specification
The input consists of one integer Y (0 Y 10000), representing the starting year.
Output Specification
The output will be the single integer D, which is the next year after Y with distinct digits.
Sample Input 1
1987
Output for Sample Input 1
2013
Sample Input 2
999
Output for Sample Input 2
1023
Here's my code:
#include <iostream>
using namespace std;
int main()
{
int year;
cin>>year;
year++;
int a=year/1000 %10;
int b=year/100 %10;
int c=year/10 %10;
int d=year% 10;
while(a==b||b==c||c==d)
{
year++;
int a=year/1000 %10;
int b=year/100 %10;
int c=year/10 %10;
int d=year %10;
}
cout<<a<<b<<c<<d;
return 0;
}
I can't seem to get the loop going,anyone who could tell me what i did wrong?
inside the while loop, you're redefining a,b,c,d as local variables. I assume you only wanted one instance of a, b, c, and d.
See this thread : http://www.cplusplus.com/forum/beginner/123116/
good luck!