zoukankan      html  css  js  c++  java
  • 找水王

    package Test;
    
    public class t {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            System.out.print("原始数据:");
            char[] a={'1','2','2','3','2','1','2','2','2','1'};
            //char[] a={'1','3','3','3','2','3','3','3','2','3','1'};
            //char[] a={'1'};
            //char[] a={'1','3','3'};
            int n=a.length;
             for(int j=0;j<n;j++){
                   System.out.print(a[j]+" ");
                   }
             System.out.println();
            System.out.print("变化过程:");
            int i=0;
           while(i<n){
           if(i+1>=n){break;}
           else{
            if(a[i]==a[i+1]){
                i++;
            }
            else{
                a[i]='*';
                a[i+1]='*';
                i+=2;
            }//if...else...
          }
                }
           
           System.out.println();
           for(int j=0;j<n;j++){
               System.out.print(a[j]+" ");
           }
           System.out.println();
           System.out.print("找出结果:");
           for(int j=0;j<n;j++){
                if(a[j]!='*'){
                   System.out.println(a[j]);
                   break;
               }
           }
    
        }
    }

    结果截图:

  • 相关阅读:
    计算几何
    差三角
    约瑟夫
    字符编码
    河南省赛之Substring
    移动字母
    抽屉原理
    不要为了完成代码而写代码
    分布式文件系统优化
    降低代码的复杂度
  • 原文地址:https://www.cnblogs.com/Amyheartxy/p/6736268.html
Copyright © 2011-2022 走看看