It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
1987
2013
2013
2014
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int a,b,c,d,e,n;
scanf("%d",&n);
while (n<=10000)
{
n++;
a=n%10;b=n%100/10;c=n/1000;d=n%1000/100; // 确定个十百千位
if (a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d) // 判断各位不同
{
return 0*printf("%d",n);}
}
}
重点是怎么找出个十百千的数,找到就好了,
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.
The only line contains an integer n (1 ≤ n ≤ 1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).
40047
NO
7747774
YES
1000000000000000000
NO
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int l,b=0;
char a[19999];
gets(a);
l=strlen(a);
for (int i=0;i<l;i++)
if(a[i]=='4'||a[i]=='7')
b++; // 计数
printf((b==4||b==7)?"YES":"NO");
}
这两道题都比较简单,多练A题也能学到c++语言的一些语法。希望自己能越学越好
