|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Danmoits 于 2020-11-15 08:27 编辑
任务描述
本关任务:输入正整数x(2≤x≤79),输出所有形如abcde/fghij=x的表达式,其中i-j由不同的数字0~9组成。
编程要求
在右侧编辑器补充代码,输入x后输出形如abcde/fghij=x的表达式。
测试输入:32;
预期输出:75168/02349=32
测试输入:12;
预期输出:
45792/03816=12
73548/06129=12
89532/07461=12
91584/07632=12
- #include<stdio.h>
- int main()
- {
- int h,i,l,m,k,n,p=0,count=0;
- double num[100000];
- double num_[100000];
- int repeat[5];
- double div;
- for(i=0;i<100000;i++)
- {
- num[i]=i;
- /*把0到99999的所有数存入数组*/
- }
- for(i=0;i<100000;i++)
- {
- for(h=0;h<5;h++,num[i]/10)
- {
- repeat[h]=(int)num[i]%10;
- /*repeat[h]存放每一位数字*/
- }
- for(l=0;l<5;l++)
- {
- for(m=0;m<5;m++)
- {
- if(repeat[l]==repeat[m])
- {
- count=1;
- }
- }
- }
- /*如果有重复数字,count不为0*/
- if(count==0)
- {
- num_[p]=num[i];
- p++;
- }
- count=0;
- }
- }
- scanf("%d",&n);
- for(i=0;i<100000;i++)
- {
- for(k=0;k<100000;k++)
- {
- div=num[i]*1.0/num[k];
- if(div==n)
- printf("%05.0f/%05.0f=%d\n",num[i],num[k],n);
- }
- }
- return 0;
- }
复制代码
这是我的代码,报错信息:(表示自己看不懂)
src/step10/step10_main.c:40:11: error: expected declaration specifiers or ‘…’ before string constant
scanf(“%d”,&n);
^~
src/step10/step10_main.c:40:16: error: expected declaration specifiers or ‘…’ before ‘&’ token
scanf(“%d”,&n);
^
src/step10/step10_main.c:41:5: error: expected identifier or ‘(’ before ‘for’
for(i=0;i<100000;i++)
^
src/step10/step10_main.c:41:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
for(i=0;i<100000;i++)
^
src/step10/step10_main.c:41:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
for(i=0;i<100000;i++)
^~
src/step10/step10_main.c:50:5: error: expected identifier or ‘(’ before ‘return’
return 0;
^~
src/step10/step10_main.c:51:1: error: expected identifier or ‘(’ before ‘}’ token
}
^
可以修改我的代码,也可以提供新的代码。(运行时间在20s以内)
本帖最后由 jackz007 于 2020-11-15 13:12 编辑
即时完成的版本来了
- #include <stdio.h>
- int check(int a , int b)
- {
- int d[10] = {0} , e[10] = {0} , i , k , r ;
- if(a < 100000) for(k = a , i = 0 ; k ; k /= 10 , i ++) e[i] = k % 10 ;
- if(b < 100000) for(k = b , i = 5 ; k ; k /= 10 , i ++) e[i] = k % 10 ;
- for(i = 0 ; i < 10 ; i ++) d[e[i]] ++ ;
- for(r = 1 , i = 0 ; i < 10 ; i ++) {
- if(! d[i]) {
- r -- ;
- break ;
- }
- }
- return r ;
- }
- main(void)
- {
- int i , m , n ;
- scanf("%d" , & n) ;
- for(m = 0 , i = 1234 ; i * n < 98766 ; i ++) {
- if(check(i , i * n)) {
- m ++ ;
- printf("%d / %d = %d\n" , i * n , i , n) ;
- }
- }
- }
复制代码
|
|