zoukankan      html  css  js  c++  java
  • 判断一个整形数是不是回文

    所谓回文,也就是给定的整形数颠倒过来与原来的数大小相等。

    首先是C实现:

     1 #include <string.h>
     2 #include <stdio.h>
     3 #include <stdlib.h>
     4 int main()
     5 {
     6     int x=12321;
     7     int m=0;
     8     int k=0;
     9     int a[5];
    10     while(x>0){
    11       m=x%10;
    12       x=x/10;
    13       a[k]=m;
    14       k++;
    15     }
    16     k=k-1;
    17     for(int i=0;i<k/2;i++){
    18 
    19     if(a[i]!=a[k-i]) printf("你所输入的数字不是回文");
    20 
    21     }
    22     printf("你所输入的数字是回文");
    23     return 0;
    24 }

    接下来是栈实现数的翻转,进而比较是否变换前后相等:

     1 package uhio;
     2 import java.util.*;
     3 public class  Palindrome {
     4     public static void main(String[] args) {
     5         
     6         int a=123321;
     7         int b=a;
     8         int m=0,k=0;
     9         Stack<Integer> stack1=new Stack<Integer>();
    10         while(a>0){
    11             m=a%10;
    12             stack1.push(m);
    13             a=a/10;
    14            
    15         }
    16         while(!stack1.isEmpty()){
    17             int p=stack1.pop();
    18             k=b%10;
    19             if(k!=p) System.out.print("输入非回文数");
    20             b=b/10;
    21         }
    22         System.out.print("输入是回文数");
    23     }
    24 
    25 }
  • 相关阅读:
    组策略导入导出secedit
    ipad常见错误
    ipad系统路径
    内核操作注册表例子
    WoW64子系统
    win2003 shutdown命令
    regedit 导入注册表
    windbg for CLR
    WM_POWERBROADCAST
    OpenSSL命令
  • 原文地址:https://www.cnblogs.com/lujun1949/p/5823343.html
Copyright © 2011-2022 走看看