日期:2019.4.25

博客期:061

星期四

今天是把很久之前的那个相关程序——一维数组的最大和的子数组的求取信息,我们今天的任务就是把每一步的信息都要进行输出查看!

如下图:

  

 package pvp;

 import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner; public class TestPlay6 {
public static void run(){
File f = new File("data/data.txt");
if(!f.exists())
{
System.out.println("文件不存在!");
System.exit(0);
}
//存储导入内容
String str;
//内容
Scanner sc = null;
try {
sc = new Scanner(f);
} catch (FileNotFoundException e1) {
System.out.println("文件不存在!");
System.exit(0);
}
//最大值
BigInteger rmax = new BigInteger("0");
//正数总值
BigInteger Tnum = new BigInteger("0");
//负数总值
BigInteger Fnum = new BigInteger("0");
//记录是否发生转变
int sis = 0;
//标记是第几程度
int attitude = 0; BigInteger start = BigInteger.ZERO,end = BigInteger.ZERO;
BigInteger true_start = BigInteger.ZERO,true_end = BigInteger.ZERO;
//循环
try
{
BigInteger sis_s = rmax;
BigInteger seat = new BigInteger("0");
if(!sc.hasNext())
{
System.out.println("文件内容为空!");
System.exit(0);
}
while(sc.hasNext())
{
str = sc.next();
BigInteger p = new BigInteger(str);
seat = seat.add(BigInteger.ONE);
end = seat;
if(attitude==0) //---------------------------------------[寻找第一个正数]
{
if(p.compareTo(new BigInteger("0"))<=0)
;
else
{
start = seat;
Tnum = p;
attitude = 1;
}
}
else if(attitude==1) //---------------------------------------[上一个数为正数]
{
if(p.compareTo(new BigInteger("0"))<0)
{
if(sis==0)
{
sis = 1;
Fnum.add(p);
}
else
{
Fnum = p;
}
attitude = -1;
}
else
{
Tnum = Tnum.add(p);
} if(Tnum.compareTo(rmax)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
}
else //---------------------------------------[上一个数为负数]
{
if(p.compareTo(new BigInteger("0"))>0)
{
attitude = 1;
if(Tnum.compareTo(new BigInteger("0").subtract(Fnum))>0)
{
Tnum = Tnum.add(Fnum).add(p);
}
else
{
Tnum = p;
start = seat;
}
}
else
{
Fnum = Fnum.add(p);
}
}
if(p.compareTo(rmax)>0)
{
rmax = p;
true_start = start;
true_end = end;
}
if(p.compareTo(Tnum)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
if(rmax.equals(sis_s))
System.out.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
else
{
System.err.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
sis_s = rmax;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
} }
catch( NumberFormatException e){
System.out.println("输入内容不是数字!");
System.exit(0);
}
sc.close();
}
public static void run2(int ls){
File f = new File("data/data.txt");
if(!f.exists())
{
System.out.println("文件不存在!");
System.exit(0);
}
//存储导入内容
String str;
//内容
Scanner sc = null;
try {
sc = new Scanner(f);
} catch (FileNotFoundException e1) {
System.out.println("文件不存在!");
System.exit(0);
}
//最大值
BigInteger rmax = new BigInteger("0");
//正数总值
BigInteger Tnum = new BigInteger("0");
//负数总值
BigInteger Fnum = new BigInteger("0");
//记录是否发生转变
int sis = 0;
//标记是第几程度
int attitude = 0; BigInteger start = BigInteger.ZERO,end = BigInteger.ZERO;
BigInteger true_start = BigInteger.ZERO,true_end = BigInteger.ZERO;
//循环
try
{
BigInteger sis_s = rmax;
BigInteger seat = new BigInteger("0");
if(!sc.hasNext())
{
System.out.println("文件内容为空!");
System.exit(0);
}
BigInteger sss = new BigInteger(Integer.toString(ls));
while(sc.hasNext())
{
str = sc.next();
BigInteger p = new BigInteger(str);
seat = seat.add(BigInteger.ONE);
end = seat;
if(attitude==0) //---------------------------------------[寻找第一个正数]
{
if(p.compareTo(new BigInteger("0"))<=0)
;
else
{
start = seat;
Tnum = p;
attitude = 1;
}
}
else if(attitude==1) //---------------------------------------[上一个数为正数]
{
if(p.compareTo(new BigInteger("0"))<0)
{
if(sis==0)
{
sis = 1;
Fnum.add(p);
}
else
{
Fnum = p;
}
attitude = -1;
}
else
{
Tnum = Tnum.add(p);
} if(Tnum.compareTo(rmax)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
}
else //---------------------------------------[上一个数为负数]
{
if(p.compareTo(new BigInteger("0"))>0)
{
attitude = 1;
if(Tnum.compareTo(new BigInteger("0").subtract(Fnum))>0)
{
Tnum = Tnum.add(Fnum).add(p);
}
else
{
Tnum = p;
start = seat;
}
}
else
{
Fnum = Fnum.add(p);
}
}
if(p.compareTo(rmax)>0)
{
rmax = p;
true_start = start;
true_end = end;
}
if(p.compareTo(Tnum)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
if(sss.compareTo(seat)<=0)
{
if(rmax.equals(sis_s))
System.out.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
else
{
System.err.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
sis_s = rmax;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
} }
catch( NumberFormatException e){
System.out.println("输入内容不是数字!");
System.exit(0);
}
sc.close();
}
public static void FileMaker(BigInteger leng,BigInteger min,BigInteger max){
File f = new File("data/data.txt");
if(!f.exists())
{
try {
f.createNewFile();
} catch (IOException e) {
//Do Nothing...
}
}
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
} catch (FileNotFoundException e) {
System.out.println("文件不存在!");
System.exit(0);
}
Random ra = new Random(System.currentTimeMillis());
BigInteger bi = new BigInteger("1"); BigInteger sumL = max.subtract(min).add(BigInteger.ONE); while(bi.compareTo(leng)<=0)
{
long x = ra.nextLong();
BigInteger bnum = new BigInteger(Long.toString(x));
bnum = bnum.mod(sumL).add(min);
pw.println(bnum.toString());
bi = bi.add(BigInteger.ONE);
}
pw.close();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入数据量:");
String str = sc.next();
System.out.println("请输入数据范围:");
String str1 = sc.next();
String str2 = sc.next();
System.out.println("确定是否查看关键步骤");
boolean isKey = false;
try{
isKey = sc.nextBoolean();
BigInteger leng = new BigInteger(str);
BigInteger num1 = new BigInteger(str1);
BigInteger num2 = new BigInteger(str2);
if(num1.compareTo(num2)==0)
throw new Exception();
else if(leng.compareTo(BigInteger.ZERO)<0)
throw new Exception();
else
{
if(num1.compareTo(num2)<0)
FileMaker(leng,num1,num2);
else
FileMaker(leng,num2,num1);
}
}catch(Exception e){
System.out.println("爷爷!出现问题了!");
System.exit(0);
} if(!isKey)
run();
else
{
run();
try{
int l = sc.nextInt();
run2(l);
}catch (Exception e){
//Do Nothing...
}
}
sc.close();
}
}

TestPlay6

Java软件工程的弹幕调试原则的更多相关文章

  1. ndk-gdb 对java/native code联合调试(升级版)

    之前写过一篇 关于android native 开发,调试的文章(http://www.cnblogs.com/yaozhongxiao/archive/2012/03/13/2393959.html ...

  2. developerWorks 中国 技术主题 Java technology 文档库 Java 性能测试的四项原则

    转-https://www.ibm.com/developerworks/cn/java/j-lo-java-performance-testing/?cm_mmc=dwchina-_-homepa ...

  3. Java设计模式的6大原则

    Java设计模式的6大原则 1.开闭原则(Open Close Principle) 开闭原则就是说对扩展开放,对修改关闭.在程序需要进行拓展的时候,不能去修改原有的代码,实现一个热插拔的效果.简单来 ...

  4. 图解Java设计模式之设计模式七大原则

    图解Java设计模式之设计模式七大原则 2.1 设计模式的目的 2.2 设计模式七大原则 2.3 单一职责原则 2.3.1 基本介绍 2.3.2 应用实例 2.4 接口隔离原则(Interface S ...

  5. RASP | 远程Java应用的RASP调试教程

    远程Java应用的RASP调试教程 介绍 Java RASP是基于Java Agent技术实现的,而Java Agent代码无法独立启动,必须依赖于一个Java运行时程序才能运行. 如何调试一个Jav ...

  6. 有效处理java异常的三个原则

    Java中异常提供了一种识别及响应错误情况的一致性机制,有效地异常处理能使程序更加健壮.易于调试.异常之所以是一种强大的调试手段,在于其回答了以下三个问题: 什么出了错? 在哪出的错? 为什么出错? ...

  7. Java GC 专家系列5:Java应用性能优化的原则

    本文是GC专家系列中的第五篇.在第一篇理解Java垃圾回收中我们学习了几种不同的GC算法的处理过程,GC的工作方式,新生代与老年代的区别.所以,你应该已经了解了JDK 7中的5种GC类型,以及每种GC ...

  8. Java Eclipse进行断点调试

    如何调试Java程序? 大家最开始学习Java,都会觉得IDE调试好高端有木有,其实很简单了. 下文会尽量简单直观的教会你在Eclipse中调试,其他的IDE调试步骤也是类似的. 1.在你觉得有错的地 ...

  9. JAVA设计模式之依赖倒转原则

    3.1 依赖倒置原则的定义 依赖倒置原则(Dependence Inversion Principle,简称DIP)这个名字看着有点别扭,“依赖”还“倒置”,这到底是什么意思?依赖倒置原则的原始定义是 ...

随机推荐

  1. 使用Yii2的Web框架搭建微服务框架

    方法 使用自己的Yii2镜像作为基础 使用Yii2的Web框架搭建,为了节省搭建Yii2框架的时间,直接使用现有的Yii2项目,删除了业务相关的逻辑类,将这个代码库作为搭建微服务框架的基础,本身已经积 ...

  2. Linux学习之路4——文件IO打开、创建、读写操作

    1.使用man 2 open.man 2 creat.man 2 write.man 2 read命令获取头文件 语法: int open(const char *pathname, int flag ...

  3. luogu P1723 高手过愚人节

    打算下周讲课就讲Manacher了 所以百度了一下相关题目,发现了一道千古好题 这道题没想到是一道模板题,模板中的模板 简要说一下思路,我们先复制一遍模板(甚至变量都不用改 然后唯一的区别就是要求的是 ...

  4. Luogu3732 [HAOI2017] 供给侧改革 【后缀数组】【线段树】【乱搞】

    题目分析: 这道题我是乱搞的,因为他说$01$串是随机的. 那么我们可以猜测能够让LCP变大的地方很少.求出后缀数组之后可能让LCP变大的地方就等价于从大到小往height里动态加点同时维护这个点左右 ...

  5. 洛谷P3719 REXP 题解

    题目 一道考验递归的题目,在面对这种字符串处理的题时,还是应该用递归这种比较好看懂而且比较简单写的算法. \(code\) ```c++ // luogu-judger-enable-o2 inclu ...

  6. HAOI2018苹果树

    题解 首先所有生成树的情况树是\(n!\)的,因为第一次有1中方法,第二次有两种放法,以此类推... 然后我们发现距离这种东西可以直接枚举每条边算贡献. 于是我们枚举了一个点\(i\),又枚举了这个点 ...

  7. JDK源码分析(9) LinkedHashMap

    概述 LinkedHashMap是一个关联数组.哈希表,它是线程不安全的,允许key为null,value为null.他继承自HashMap,实现了Map<K,V>接口.其内部还维护了一个 ...

  8. 小白月赛13 B小A的回文串 (马拉车算法求最长回文子串)

    链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  9. Centos下MariaDB操作

    MariaDB简介 MariaDB是mysql数据库的一个分支,操作几乎和mysql一样 MariaDB安装.启动.停止 # 安装 yum -y install mariadb mariadb-ser ...

  10. iOS程序员 如何做到升职加薪,5年 开发经验 码农 笔记送给你!

    前言: 对于我们绝大多数人来说,工作最基本的意义是我们可以通过自己的劳动换取酬劳来养活自己,尤其是对于刚毕业的学生,拥有一份全日制的工作意味着自己走出校园,踏上社会,自己真正开始独立起来. 在养活自己 ...