1 条题解
-
0
C :
#include <stdio.h> #include <string.h> int main(){ char strNum[15]; for(int i=0; i<256; i++){ int ans = i*i; sprintf(strNum, "%d", ans); int len = strlen(strNum); int j; for(j=0; j<len/2; j++){ if(strNum[j] != strNum[len-1-j]){ break; } } if(j >= len/2){ printf("%d\n", i); } } return 0; }
C++ :
#include <stdio.h> #include <string.h> int main(){ char strNum[15]; for(int i=0; i<256; i++){ int ans = i*i; sprintf(strNum, "%d", ans); int len = strlen(strNum); int j; for(j=0; j<len/2; j++){ if(strNum[j] != strNum[len-1-j]){ break; } } if(j >= len/2){ printf("%d\n", i); } } return 0; }
Pascal :
var i,j:longint; s:string; begin for i:=0 to 256 do begin str(i*i,s); for j:=1 to length(s) div 2 do if s[j]<>s[length(s)-j+1] then break; if s[j]=s[length(s)-j+1] then writeln(i); end; end.
Java :
import java.util.*; public class Main{ public static void main(String args[]){ for(int i=0;i<=256;i++){ int ii=i*i; int iii=ii; int ixi=0; while(iii>0){ ixi*=10; ixi+=iii%10; iii/=10; } if(ixi==ii) System.out.println(i); } } }
Python :
# coding=utf-8 def isSquareEq(i): sq = str(i ** 2) i = 0 j = len(sq) - 1 while i <= j and sq[i] == sq[j]: i += 1 j -= 1 if i < j: return False return True for i in range(213): if isSquareEq(i): print(i)
C# :
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 对称平方数 { class Program { static void Main(string[] args) { for (int i = 0; i <= 256; i++) { string s = (i * i).ToString(); int j; for (j = 0; j < s.Length / 2; j++) { if (s[j] != s[s.Length - 1 - j]) break; } if (j >= s.Length / 2) Console.WriteLine("{0}", i); } } } }
- 1
信息
- ID
- 45
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 9
- 标签
- 递交数
- 13
- 已通过
- 3
- 上传者