zoukankan      html  css  js  c++  java
  • zzulioj--1825-- 会长爱数学(模拟)

    1825: 会长爱数学

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 6  Solved: 2

    SubmitStatusWeb Board

    Description

    陆爸爸不仅是个爱晨刷的girl,也特别喜欢数学呢。然而她已经不满足于高数线代这些简单玩意了,
    她要自己定义一种运算改变世界!有一天她垂死梦中惊坐起,突然就想到了一种新的运算F(X)。
    如F(123)=1*2+2*3+3*1=11。陆爸爸发现对于所有的数字来说不停的F()会进入一个循环,
    f(123)=11 f(11)=2  f(2)=4   f(4)=16 f(16)=12 f(12)=4,循环节的大小就是G(x)。
    现在陆爸爸要用自己的方法考验你,给你初始的x,请你计算G(x)。

    Input

    多实例。每组实例输入一个数字X

    Output

    输出G(X)

    Sample Input

    123

    Sample Output

    3






    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int num[10010],f[1000];
    int main()
    {
    	int n;
    	while(scanf("%d",&n)!=EOF)
    	{
    		int cnt=1,ans;
    		int flog=0;
    		if(n==0)
    		{
    			printf("1
    ");continue;
    		}
    		else			
    		{
    			while(1)
    			{	
    				memset(num,0,sizeof(num));
    				f[cnt]=n;
    				int t=0;
    				while(n)
    				{
    					num[t++]=n%10;
    					n/=10;
    				}
    				if(t>1)
    				{
    					for(int i=1;i<t;i++)
    					n+=num[i]*num[i-1];
    					n+=num[0]*num[t-1];
    				}
    				else n=f[cnt]*f[cnt];
    				for(int i=1;i<=cnt;i++)
    				{
    					if(f[i]==n)
    					{
    						ans=cnt-i+1;flog=1;
    						break;
    					}
    				}
    				if(flog) break;
    				cnt++;
    			}
    		}
    		printf("%d
    ",ans);
    	}
    	return 0;
    }
    


  • 相关阅读:
    表达式求解
    block的使用
    UITableView 知识点总结
    UIView 实战习题
    三、 UIView封装的简单动画
    二、 UIButton的使用总结
    一、 UIView的常见属性
    iOS开发网络篇之文件下载、大文件下载、断点下载
    多线程-NSthread
    二.初始化方法
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273616.html
Copyright © 2011-2022 走看看