[坑]1430.幸运数字

1430.幸运数字
Time Limit: 1000 MS         Memory Limit: 65536 K 
Total Submissions: 78 (29 users)         Accepted: 11 (11 users)

Description

每个人都有自己喜欢的数字。 若一个人喜欢的数字为4和7, 那么我们认为所有只由4和7构成的正整数都为他的幸运数字, 例如: 44, 7, 477都是幸运数字, 而14, 70都不是幸运数字。 这道题目的要求为, 给定一个正整数k, 和n个幸运数字ai (0 <= ai <= 9), 需要你求出大于k的最小幸运数字。

Input

输入的第一行有一个整数n (1 <= n <= 10), 接下来的一行有n个互不相同的整数ai (0 <= ai <= 9), 代表了幸运数字, 再接下来的一行有一个整数k (1 <= k <= 1,000,000,000,000,000,000)。

Output

输出一个大于k的最小幸运数字, 若答案不存在, 则输出"Impossible"。

Sample Input

2
4 7
48

Sample Output

74

Source
doraemon @ xmu



苣蒻伤不起。。

写出来Compile Error了。。。


代码如下:

#include<stdio.h>
#define MAXN 100000000000000000000000
int n, ai[10];
long long k;

int check(long long num)
{
    while (num)
    {
        int tmp = num % 10;
        num /= 10;
        for (int i = 0; i < n; i++)
            if (ai[i] == tmp)
                break;
            else if (ai[i] != tmp && i == n-1)
                return 0;
    }
    return 1;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &ai[i]);
    scanf("%lld", &k);
    k++;
    while (!check(k) && k <= MAXN)
        k++;
    k == MAXN ? printf("Impossible") : printf("%lld", k);
    return 0;
}

错误信息如下:

### Compile Error ###
./Main/main.c: In function ‘check’:
./Main/main.c:12: error: ‘for’ loop initial declaration used outside C99 mode
./Main/main.c: In function ‘main’:
./Main/main.c:24: error: ‘for’ loop initial declaration used outside C99 mode
./Main/main.c:28:30: warning: integer constant is too large for its type
./Main/main.c:28: warning: integer constant is too large for ‘long’ type
./Main/main.c:28: warning: comparison is always true due to limited range of data type
./Main/main.c:30:10: warning: integer constant is too large for its type
./Main/main.c:30: warning: integer constant is too large for ‘long’ type
./Main/main.c:30: warning: comparison is always false due to limited range of data type


只允许在 C99 模式下使用‘for’循环初始化声明

for 循环内不能定义。。。

把i的定义拉到外面过来,后上交,结果超时了。。。

最近老是悲催的超时。。。


错误信息

Test # 1.....			Accepted
	Use Time 0ms, Use Memory 36KB
Test # 2.....			Accepted
	Use Time 0ms, Use Memory 36KB
Test # 3.....			Time Limit Exceed
	Use Time 1004ms, Use Memory 32KB

The Result is Time Limit Exceed.
Terminated On Test #3
	Use Time 1004ms, Use Memory 36KB

第三例1004。。。你用了什么例子。。。

弱菜能力不够,暂时不能A掉这题。。。

又留坑了。。。

原文地址:https://www.cnblogs.com/java20130723/p/3212183.html