首页 > 其他 > 详细

Section 1.2.4 Palindromic Squares 大水

时间:2015-07-09 00:43:24      阅读:253      评论:0      收藏:0      [点我收藏+]

http://www.wzoi.org/usaco/12%5C501.asp

 

patpat 学习了一个新的stl函数

 

eg.

  string poi = "poi";

  reverse(poi.begin(), poi.end());

就把poi变成了"iop"

 

技术分享
#include <bits/stdc++.h>
using namespace std;
int base;

string trans(int temp){
    int j, ch;
    string ans = "";
    while(temp){
        ch = temp % base;
        if(ch < 10) ans += ch + 0;
        else ans+= ch - 10 +A;
        temp /= base;
    }
    return ans;
}
int main()
{

    #ifndef poi
        freopen("palsquare.in","r",stdin);
        freopen("palsquare.out","w",stdout);
    #endif
    string str;
    scanf("%d", &base);
    int i, temp, j, ch, len;
    for(i = 1; i <= 300; i++){
        str = trans(i * i);
        len = str.length();
        for(j = 0; j <= len / 2; j++){
            if(str[j] != str[len - j - 1])  break;
        }
        if(j <= len / 2)    continue;
        string tp = trans(i);reverse(tp.begin(), tp.end());
        cout<<tp<<" "<<str<<endl;

    }
    return 0;
}
View Code

 

Section 1.2.4 Palindromic Squares 大水

原文:http://www.cnblogs.com/bbbbbq/p/4631734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!