zoukankan      html  css  js  c++  java
  • java CG

    进制转换

    package ch2;
    import java.util.Scanner;
    public class CG0311_2 {
        public static void main(String [] args) {
            Scanner sc = new Scanner(System.in); 
            long  res=0 ,base = 1;
            String str;
            str = sc.next();
            int len = str.length();
            for(int i = len-1;i>=0;i--) {
                if( str.charAt(i)=='1' ) {
                    res += base;
                }
                base*=2;
            } 
            System.out.println(res);
            sc.close();
        }
    }

    double

    package ch2;
    import java.util.Scanner;
    public class CG031101 {
        public static void main( String [] args ) { 
            Scanner in = new Scanner(System.in);
            long a,b;
            a = in.nextInt();
            b = in.nextInt(); 
            System.out.printf("128-bit hexadecimal number:
    %016x%016x
    ",a,b);
            a = a<<1;
            if( b<=-1 )    a=a+1; 
            b=b<<1;
            System.out.printf("After doubling:
    %016x%016x
    ",a,b);
        }
    }
     

    找点:在本列和本行都是最大。

    package CG;
    
    import java.util.Scanner;
    
    public class array_1 {
        public static void main(String [] args) {
            Scanner sc=new Scanner(System.in);
            int arr[][] = new int[12][12];
            int m,n;
            n = sc.nextInt();
            m = sc.nextInt();
            for( int i = 1;i<=n ;i++ ) {
                for(int j = 1;j<=m;j++) {
                    arr[i][j] = sc.nextInt();
                }
            }
            for( int i = 1;i<=n ;i++ ) {
                for(int j = 1;j<=m;j++) {
                    int flag = 1;
                    for(int jj = 1;jj<=m;jj++) if( arr[i][jj]>arr[i][j] ) flag = 0;
                    for(int ii = 1;ii<=n;ii++) if( arr[ii][j]>arr[i][j] ) flag = 0;
                    if(flag==1) {
                        System.out.println( arr[i][j]+" "+i+" "+j);
                    }
                     
                }System.out.println();
            }
                    
        }
    }

    二分查找

     package CG;
    import java.util.Scanner;
    public class array_2 {
        public static int find(int []arr,int l,int r,int res){
            if( l == r ) {
                if( arr[l]==res ) return l;
                else return 0;
            } 
            int mid = (l+r)/2;
            if( arr[mid] == res ) return mid;
            else if( arr[mid]<res ) return find(arr,mid+1,r,res);
            return find(arr,l,mid-1,res);
        }
        public static void main(String[] args) { 
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int []arr=new int[n+5];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            int res=sc.nextInt(); 
            System.out.println(find(arr,0,n-1,res));
        }
    }

    表的“异或”

    package CG; 
    import java.util.*; 
    public class array_3 {
        public static void main(String[] args) {
            HashSet<Integer> Set1 = new HashSet<>();
            HashSet<Integer> Set2 = new HashSet<>();
            int arr[] = new int[45];
            int n,m;
            Scanner sc = new Scanner( System.in );
            n = sc.nextInt();
            for(int i = 1; i<= n; i++) {
                arr[i] = sc.nextInt();
                Set1.add(arr[i]);
            } 
            m = sc.nextInt();
            for(int i = n+1; i<= m+n; i++) {
                arr[i] = sc.nextInt();
                if( Set1.contains(arr[i]) ) Set2.add(arr[i]);
            }
            Arrays.sort(arr,1,m+n+1); 
            for(int i = 1;i <= m+n ; i++) {
                if( !Set2.contains(arr[i]) ) System.out.print( arr[i]+" " );
            }
        }
    }
  • 相关阅读:
    VB C# 语法对比图 (代码实例)
    改进了的一个邮件发送类
    什么时候应该使用 ==?什么时候应该使用 Equals?
    c#写的贪吃蛇小游戏
    七招制胜ASP.NET应用程序开发
    SQL Server开发人员应聘常被问的问题汇总
    DataTable中数据记录的统计
    ASP.NET中数据库数据导入Excel并打印
    在.NET中得到计算机硬件信息的一些功能
    C#.NET 中的类型转换
  • 原文地址:https://www.cnblogs.com/SunChuangYu/p/12462160.html
Copyright © 2011-2022 走看看