1 条题解
-
0
C :
#include<stdio.h> int huiWen(int x) { int h=0,t=x; while(x>0){ h=h*10+x%10; x/=10; } if(h==t){ return 1; }else{ return 0; } } int main() { int n,i,c=0; scanf("%d",&n); for(i=1;i<=n;i++){ if(huiWen(i)){ c++; } } printf("%d",c); return 0; }C++ :
#include <iostream> #include <cmath> using namespace std; bool sushu(int n){ int i; bool f=true; for(i=2;i<=sqrt(n);i++){ if(n%i==0){ f=false; break; } } if(n<=1){ f=false; } return f; } bool huiwen(int n){ bool f=false; int g=n%10,s=n/10%10,b=n/100%10,q=n/1000%10,w=n/10000; if(n<=99&&g==s||n<=9){ f=true; } else if(n>99&&n<=999&&g==b){ f=true; } else if(n>999&&n<=9999&&g==q&&s==b){ f=true; } else if(n>=10000&&g==w&&s==q){ f=true; } return f; } int main(){ int n,i,c=0; cin>>n; for(i=1;i<=n;i++){ if(huiwen(i)==true){ c++; } } cout<<c<<endl; }Pascal :
var a,b,c,d,e,f,g,huiwen:longint;s:string; begin read(a); for b:=1 to a do begin str(b,s); d:=length(s); if d=1 then inc(huiwen); if d=2 then if s[1]=s[2] then inc(huiwen); if d=3 then if s[1]=s[3] then inc(huiwen); if d=4 then if (s[1]=s[4]) and (s[2]=s[3]) then inc(huiwen); end; write(huiwen); end.Java :
import java.util.Scanner; public class Main{ public static void main(String[] args) { int n=new Scanner(System.in).nextInt(); int count=0; for(int i=1;i<=n;i++){ if(isHws(i)){ count++; } } System.out.println(count); } public static boolean isHws(int n){ boolean f=true; char[] charArray=String.valueOf(n).toCharArray(); for(int i=0;i<charArray.length;i++){ if(charArray[i]!=charArray[charArray.length-i-1]&&i!=charArray.length-i-1){ f=false;break; } } return f; } }Python :
def dcf(x): a = [] while x > 0: s = x % 10 x //= 10 a.insert(0, s) return a n = int(input()) l = [] s = 0 c = 0 for i in range(10, n + 1): l = dcf(i) s = len(l) if s == 2 and l[0] == l[1]: c += 1 elif s == 3 and l[0] == l[2]: c += 1 elif s == 4 and l[0] == l[3] and l[1] == l[2]: c += 1 print(c + 9)
- 1
信息
- ID
- 144
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 4
- 上传者