• USACO Palindromic Squares


      看一下n2的base进制是不是回文串, 是的话输出来即可, 直接暴力枚举:

    /*
        ID: m1500293
        LANG: C++
        PROG: palsquare
    */
    
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    int B;
    
    int a[100], len;
    
    bool check(int n)
    {
        len = 0;
        int tp = n*n;
        while(tp > 0)
        {
            a[len++] = tp%B;
            tp /= B;
        }
        bool flog = true;
        for(int i=0; i<len/2; i++)
        {
            if(a[i] != a[len-1-i])
            {
                flog = false;
                break;
            }
        }
        return flog;
    }
    
    int b[100], len_b;
    
    void trans(int n)
    {
        len_b = 0;
        while(n > 0)
        {
            b[len_b++] = n%B;
            n /= B;
        }
        for(int i=len_b-1; i>=0; i--)
            if(b[i] < 10) printf("%d", b[i]);
            else printf("%c", 'A'+b[i]-10);
    }
    
    int main()
    {
        freopen("palsquare.in", "r", stdin);
        freopen("palsquare.out", "w", stdout);
        while(scanf("%d", &B) == 1)
        {
            for(int n=1; n<=300; n++)
            {
                if(check(n)) 
                {
                    trans(n);
                    printf(" ");
                    for(int i=0; i<len; i++)
                    {
                        if(a[i] < 10) printf("%d", a[i]);
                        else printf("%c", 'A'+a[i]-10);
                    }
                    printf("
    ");
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    Python 面向对象
    python Flask
    工作中的Python脚本
    python模块
    python函数
    Python小课题练习作业
    Python文件处理
    Maven 生成可执行的jar包
    Maven [ERROR] 不再支持源选项 5。请使用 6 或更高版本
    MySQL 导入导出数据
  • 原文地址:https://www.cnblogs.com/xingxing1024/p/5055449.html
Copyright © 2020-2023  润新知