原题目链接http://codeforces.com/contest/271/problem/A
这道题题目大意就是让你找比它大的最小年份,且各个位的数字不一样,拿1987来说,+1就是1988,88重复不符合题意接着+1,1989,两个9又重了,以此类推直到找到大于它的最小年份2013.我用了两个方法,不过思路都是一样的:
方法一:(因为看到题目说年份在1000到9000之间,不过不能设在1000到9000,会错)
#include<stdio.h>
#include<string.h>
int main()
{
int a,one,ten,hun,thou;
int ans,i;
while(scanf("%d",&a)!=EOF)
{
ans=0;
for(i=1000;i<=10000;i++)
{
one=i%10;
ten=i/10%10;
hun=i/100%10;
thou=i/1000;
if(one==ten||one==hun||one==thou||ten==hun||ten==thou||hun==thou||i<=a)
continue;
else
{
printf("%d\n",i);
break;
}
}
}
return 0;
}
方法二:
#include<stdio.h>
#include<string.h>
int main()
{
int a,one,ten,hun,thou;
while(scanf("%d",&a)!=EOF)
{
a++;
while(a)
{
one=a%10;
ten=a/10%10;
hun=a/100%10;
thou=a/1000;
if(one==ten||one==hun||one==thou||ten==hun||ten==thou||hun==thou)
a++;
if(one!=ten&&one!=hun&&one!=thou&&ten!=hun&&ten!=thou&&hun!=thou)
break;
}
printf("%d\n",a);
}
return 0;
}