我怎么这么菜


私信TA

用户名:xujingcheng

访问量:16896

签 名:

Break Away

等  级
排  名 722
经  验 3761
参赛次数 4
文章发表 44
年  龄 10
在职情况 学生
学  校 NUAA
专  业

  自我简介:

毕业前学一下编程, 嗯! 是这样。

/*过段时间再改吧,先保存下来(小的整数基本没毛病)*/
#include<stdio.h>
#include"malloc.h"
#include"math.h"
int main()
{
    int n,k,count=1,flag=1,j,temp;
    long po=1;
    scanf("%d%d",&n,&k);
    int *p=(int*)malloc(k*sizeof(int));
    temp=n;
    for(j=k-1;j>=0;j--)
    {
     p[j]=temp%10;
     temp=temp/10;
    }
    po=n;
    while(flag)
    {
        count++;
        po*=n;//po=pow(n,count);精度不够
        for(j=k-1;j>=0;j--)
        {
          if(po%10!=p[j]) break;
          else po=po/10;
        }
        if(j==-1) {flag=0;count--;}
        if(count>1000) {printf("-1\n");break;}
    }
    if(flag==0) printf("%d\n",count);
    return 0;
}
 

0.0分

6 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

#include<stdio.h>
#include<math.h>
void main()
{
	int num,n;
	int i,l,x=1,w[10000];

	scanf("%d%d",&num,&n);
	if(num<pow(10,n-1))
		printf("-1\n");
	else
	{
		for(i=1;i<=10000;i++)
		{
			x*=num;
			w[i]=x%(int)pow(10,n);
			if(x>pow(10,n))
				x=w[i];
		//	printf("i=%d,x=%d,w[%d]=%d\n",i,x,i,w[i]);
		}
			for(l=1;l<i;l++)
			{
				if(w[1]==w[1+l]&&w[1+l]==w[1+2*l])
				{
					printf("%d\n",l);
					break;
				}
			}
	}
}
帮看看错在何处,总是提示运行错误,在我本地运行是没有问题的
2020-12-29 09:51:02
  • «
  • 1
  • »