zoukankan      html  css  js  c++  java
  • 关于一维数组的进一步编程,二维数组

    package 一;
    import java.io.File;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    import java.util.*;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    import java.io.BufferedReader;
    import java.io.FileOutputStream;
    import java.lang.Math;
    import java.io.IOException;
    import java.math.BigDecimal;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
    import java.util.Random;
    public class Maxshuzu 
    {
        public static void main(String[] args)throws IOException
        {
            File newFile = new File("D:\Shu.txt");//文本文档的位置
            if(!newFile.exists()) {
                System.out.println("文件无法打开!");
            }
            FileOutputStream out = new FileOutputStream(newFile);
        String[] S=new String[100000];
        BigDecimal[] S1=new BigDecimal[100000];//原串
        BigDecimal[] S2=new BigDecimal[100000];//现有
        System.out.println("请输入您要输入的数目:");
        int a=0;//总数
        Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        System.out.println("请输入整型数字:");
        for(int i=0;i<a;i++) {
            S[i]=" ";
        }
        for(int i=0;i<a;i++) {
            String s1;
            s1=scan.next();    
            S1[i]=new BigDecimal(s1);
            
        }int l=0;
        for(int i=0;i<a;i++) {
            System.out.println(""+(i+1)+"个是:"+S1[i]);
        }
        for(int i=0;i<a;i++) {
            out.write(String.valueOf(S1[i]).getBytes());
            out.write(String.valueOf(S[i]).getBytes());
        }
        int O=0;
        for(int i=0;i<a;i++) {
            int i1=i+1;
            int o;o=0;
            for(int j=i+1;j<a;j++)
            {    O=O+1;
                BigDecimal m=S1[i]; BigDecimal n=S1[j];
                BigDecimal N=new BigDecimal(0);BigDecimal M=new BigDecimal(0);
                o=o+1;
                if(o==1) {
                    M=n.add(m);
                    S2[O-1]=M;
                }
                else {
                    N=S2[O-2].add(n);
                    S2[O-1]=N;
                    System.out.println(n);
                }
                l=O;
    
            }
        }BigDecimal max=BigDecimal.valueOf(0);
        max=S2[0];
        int m0=0;
        int M0=0;
        for(int i=0;i<l-1;i++) {
            BigDecimal m1=BigDecimal.valueOf(0);
            BigDecimal m2=BigDecimal.valueOf(0);
            m1=S2[i];
            m2=S2[i+1];
            int q=2;
            if(max.compareTo(m1)==-1)max=m1;
            if(max.compareTo(m2)==-1)max=m2;
            System.out.println("是否要回滚,回滚-1,不-2");
            q=scan.nextInt();
            for(int i1=0;i1<a;i1++)
            {
                for(int i2=i1+1;i2<a;i2++)
                {
                    M0=M0+1;
                    System.out.println(""+M0+"");
                    System.out.println("已经比较了"+M0+"个子数组");
                    System.out.println("从第"+(i1+1)+"到第"+(i2+1));
                    System.out.println("最大子数组和:"+max);
                    System.out.println('
    ');
                    try{Thread.sleep(1000);}catch(Exception e){}
                    if(q==1)
                    {System.out.println("请输入回退到第几步:");
                    M0=scan.nextInt();
                    M0=M0-1;
                    System.out.println(M0);
                    i2=M0;
                    }
                }
                
            }
    
        }
        
        if(max.compareTo(S1[0])==-1) max=S1[0];
        if(max.compareTo(S1[a-1])==-1)max=S1[a-1];
        System.out.println("最大数"+max);
        out.write(String.valueOf("最大数:").getBytes());
        out.write(String.valueOf(max).getBytes());
        out.flush();
        out.close();
        FileReader reader=new FileReader("D:\Shu.txt");
        BufferedReader br=new BufferedReader(reader);
        String line;
        while((line=br.readLine())!=null) {
            System.out.println(line);
        }
        }
    }

  • 相关阅读:
    leetcode-62-Unique Paths
    [leetcode-64-Minimum Path Sum]
    [leetcode-198-House Robber]
    [leetcode-120-Triangle]
    [leetcode-53-Maximum Subarray]
    [leetcode-303-Range Sum Query
    [leetcode-123-Best Time to Buy and Sell Stock III]
    绑定下拉框
    解决URL参数中文乱码
    html 图片拖动不出来的脚本
  • 原文地址:https://www.cnblogs.com/NCLONG/p/10771217.html
Copyright © 2011-2022 走看看