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了。。。
代碼如下:
[cpp] view plaincopyprint?#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;
}
#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