鱼C论坛

 找回密码
 立即注册
查看: 156|回复: 1

代码阅读理解

[复制链接]
发表于 3 天前 | 显示全部楼层 |阅读模式
60鱼币
本帖最后由 陈尚涵 于 2024-9-22 22:12 编辑

很简单,以下有输出"Hello World"的代码(Python和C++),只需要大致描述代码原理即可

第一个答出来的丰厚奖励

Ps.下周五,也就是9/27日晚检测答案

这里保证没有以下几点:

1.任何破坏代码可读性的行为

2.任何奇怪的变量命名

3.任何不必要的多余操作(这里指一些无用的代码)

4.两个不同语言实现没有任何差异

给出代码:

C++
#include<iostream>
using namespace std;
int rem[505],codes[]={439,659,543,547,986,145,657,876,347,874,474};
int f(int x){
        if(rem[x]!=0)return rem[x];
        if(x<=1)return 1;
        rem[x]=f(x-1)+f(x-2);
        return rem[x];
}
int g(int x){
        int t=x;
        while(t){
                int cnt=1;
                while(f(cnt)<=t)cnt++;
                cnt--;
                t-=f(cnt);
        }
        return 2*x-t;
}
int trans(int x){
        if(x%10==9){
                if(x/100==4)return 14;
                else return 42;
        }else if(x%10==3)return 48;
        else if(x%10==7){
                if(x/100==5)return 48;
                else if(x/100==6)return 24;
                else return 49;
        }else if(x%10==6){
                if(x/100==9)return 50;
                else return 47;
        }else if(x%10==5)return -30;
        else if(x%10==4){
                if(x/100==8)return 42;
                else return 33;
        }
} 
int main(){
        int j=58;
        bool k=false;
        for(int i=0;i<11;i++){
                char x;
                if(codes[i]%2==0)x=trans(g(codes[i]/2));
                else x=trans(g(codes[i]/2)+1);
                x+=j;
                if(!k&&j==60)k=true;
                else j++;
                cout<<x;
        }
        return 0;
}

Python
rem = {}
codes = [439,659,543,547,986,145,657,876,347,874,474]
def f(x):
    try:
        return rem[x]
    except:
        if(x<=1):
            return 1
        rem[x]=f(x-1)+f(x-2)
        return rem[x]
def g(x):
    t=x
    while(t):
        cnt=1;
        while f(cnt)<=t:
            cnt += 1
        cnt -= 1
        t-=f(cnt)
    return 2*x-t
def trans(x):
    if x%10==9:
        if x//100==4:
            return 14
        else:
            return 42
    elif x%10==3:
        return 48
    elif x%10==7:
        if x//100==5:
            return 48
        elif x//100==6:
            return 24
        else:
            return 49
    elif x%10==6:
        if x//100==9:
            return 50
        else:
            return 47
    elif x%10==5:
        return -30
    elif x%10==4:
        if x//100==8:
            return 42
        else:
            return 33
j=58
k=False
for i in range(11):
    x = None
    if codes[i]%2==0:
        x=trans(g(codes[i]//2))
    else:
        x=trans(g(codes[i]//2)+1)
    x+=j
    if not k and j==60:
        k=True
    else:
        j+=1
    print(chr(x),end='')

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
此帖仅作者可见
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-25 21:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表