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

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

下面是关于一些关于数字判断的题,比较简单,先来看第一题:
A. Lucky Division
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517467 are not.

Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

Input

The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

Output

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Examples
input
47
output
YES
input
16
output
YES
input
78
output
NO
Note

Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.

In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

题目说输入一个数 (n小于1000)若数含有4,7则称为完美的数 若能整除完美数 则被称为几乎完美的数,判断输入的书是否是几乎完美的数,若是则输出YES 否则输出NO  下面是代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a;
    scanf("%d",&a);
    printf(a%4==0||a%7==0||a%47==0||a%74==0||a%447==0||a%477==0||a%474==0?"YES":"NO");  //判断 并输出
}
直接对数据进行判断,最后输出,
A. George and Accommodation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output

Print a single integer — the number of rooms where George and Alex can move in.

Examples
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2

纯粹的判断数字大小的问题,输入n(小于100,大于0)再输入n行,每行两个数字(两个数均小于100,大于0)
第二个数大于第一个数+2时,记数,最后输出数,下面是代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c,d,e;
int main()
{
    cin>>a;  //  输入n
    while (a--)  //  再输入n行
        {
            cin>>b>>c;  //  输入两个数
        if(c>=b+2)
            d++;
        }
        printf("%d",d);

}

上面的题略有些骚操作  
printf(a%4==0||a%7==0||a%47==0||a%74==0||a%447==0||a%477==0||a%474==0?"YES":"NO");
直接就把判断和输出放在一起执行了
至于第二题,一开始是想用数组做,但想了想,需要中间判断,就得用cin cout
其实对于输入有很多种方式表示

 1.scanf大概用的最多的了,比较方便,2.gets  和  puts这一对是用于数组的。
3.cin cout  也很方便  举个栗子:

int a,b=0;
cin>>a>>b;  //输入a,b
cout<<a<<b;  //输出a,b

char a[100];
gets (a);  // 输入a数组
puts (a);  //输出a数组

int a=0;
scanf("%d",&a);  // 输入a
printf("%d",a);   //输出b



  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值