关于一些初级ACM竞赛题目的分析和题解(八)

关于一些初级ACM竞赛题目的分析和题解(八) 
下面两道题只是表面上复杂些而已,其实 比较简单,上题:
A. Beautiful Year
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.

Output

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.

Examples
input
1987
output
2013
input
2013
output
2014

输入n(n大于等于1000,小于等于9000,且n的个十百千位各不相同),找出比n大的并个十百千位也不同的数;
下面是代码:
#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);}

    }
}
重点是怎么找出个十百千的数,找到就好了,

A. Nearly Lucky Number
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 477444 are lucky and 517467 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.

Input

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.

Output

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

Examples
input
40047
output
NO
input
7747774
output
YES
input
1000000000000000000
output
NO
Note

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".


关于幸运数,输入一行数,若他的各位数含4,7的数为4和7则为几乎幸运的数,判断是否为几乎幸运的数,是的话输出YES,否的话输出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++语言的一些语法。希望自己能越学越好 奋斗


















ACM/ICPC(ACM International Collegiate Programming Contest, 国际大学生程序设计竞赛)是由国际计算机界历史悠久、颇具权威性的组织ACM(Association for Computing Machinery,国际计算机协会)主办的,世界上公认的规模最大、水平最高的国际大学生程序设计竞赛,其目的旨在使大学生运用计算机来充分展示自己分析问题解决问题的能力。该项竞赛从1970年举办至今已历29届,一直受到国际各知名大学的重视,并受到全世界各著名计算机公司的高度关注,在过去十几年中,APPLE、AT&T、MICROSOFTIBM等世界著名信息企业分别担任了竞赛的赞助商。可以说,ACM国际大学生程序设计竞赛已成为世界各国大学生最具影响力的国际级计算机类的赛事,是广大爱好计算机编程的大学生展示才华的舞台,是著名大学计算机教育成果的直接体现,是信息企业与世界顶尖计算机人才对话的最好机会。   该项竞赛分区域预赛国际决赛两个阶段进行,各预赛区第一名自动获得参加世界决赛的资格,世界决赛安排在每年的3~4月举行,而区域预赛安排在上一年的9~12月在各大洲举行。   ACM/ICPC的区域预赛是规模很大、范围很广的赛事。仅在2003年参加区域预赛的队伍就有来自75个国家(地区),1411所大学的3150支代表队,他们分别在127个赛场中进行比赛,以争夺全球总决赛的73个名额,其激烈程度可想而知。 2005年第30届ACM/ICPC亚洲赛区预赛共设了北京、成都、汉城、东京等11个赛站,来自亚洲各国知名高校的各个代表队进行了激烈的角逐。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值