课堂小测三

终于把补丁打好了,虽然说参考了一下他们的,过程也有些小曲折,但是终终终终终终终终终终终终终终于写完了。

import java.util.*;
import java.io.*;


public class two_3 {

		static	Scanner scanner = new Scanner(System.in);
	    static File file = new File("D:/input.txt");
		static String result = new String();//储存读取的内容
		
		 public static void main(String[] args) throws IOException {
			 
				
				if (file.exists())
				{ // 检查input.txt是否存在
					System.out.println("File already exists");
			
				}
				else
				{	
					System.out.println("File don't exists");
					
				}
			
			
				
				
				
		 
				 FileInputStream f1= new FileInputStream(file);
		       
		        
		        int length=0;
		        int length_2=0 ;
		        
		    
		    	//将数字和符号储存在String中
		        for(int i=0;i<file.length();i++) {
		        	char ch=(char)(f1.read());//循环读取文本里的字符
		    		if(ch!='\r' &&ch!='\n') {
					if(ch!=',' && ((ch>='0'&& ch<='9') || ch=='-')) {
						result+=ch;			
					}
					//补丁节点1
					else if (ch!=',' && ((ch<='0'|| ch>='9') || ch!='-')) {
						System.out.print("数据格式有误");
						System.exit(1);
					}
					else {
						result+=" ";
					}
					
		    	}
		    		}
		        
		     	        
		        f1.close();
		       
		        System.out.println(result);		        
		        
		        
		        

		        
        
		        //str字符串数组储存每个数
		        String[] str=new String[10010];

		    	str[0]="";
		    	
		        for(int j=0,i=0;j<result.length();j++) {
		    		if (result.charAt(j)!=' ')
		    			str[i]+=result.charAt(j);
		    		else {
		    			
		    			str[++i]="";
		    		}
		    	}

		        
		    	  char c = result.charAt(0);
		    	  length=(int)c-48;
		    	  char d = result.charAt(2);
		    	  length_2=(int)d-48;
		    	  
		       
		        //补丁节点2

		        if (length==0) {
					System.out.print("数据格式有误");
					System.exit(1);
		        }
		        //补丁节点3
		        for (int i = 2;i<length_2;i++) {
		        	if(str[i].length()>=8) {
		        		System.out.print("数字过大,不符合标准");
		        		System.exit(1);
		        	}
		        }
		        
		        
		        
		        
		        
		        

		    	  
		  

		    	  
		        int tempInt[][] = new int[length][length_2];
		        
		        int max = 0;
		        int tempMax = 0;//当前最大值
		        int n = 4;
		        int flag='-'-48;
		        
		        
		        
		        
		        
		        for (int i = 0; i < length; i++) {
		        	for(int j=0;j<length_2;j++) {
		        		int o = j+i*length_2+2;
		        	
		            tempInt[i][j] =Integer.parseInt(str[o]);//Integer.parseInt可以将string字符串转换为int类型
		          
		          System.out.println(tempInt[i][j]);
		           	     
		            if (i==0&&j == 0) {//第一个是元素
		                tempMax = tempInt[i][j];
		                max = tempInt[i][j];
		            } else {
		                if (tempMax < 0) {
		                    tempMax = tempInt[i][j];
		                } else {
		                    tempMax += tempInt[i][j];
		                }
		            }

		            if (tempMax > max) {
		                max = tempMax;
		            }
		            n=n+2;
		          
		        }
		       

		    }
		        System.out.println("结果是:*********");
		        System.out.println(max);
		}
	
}

  

posted @ 2022-03-19 10:06  信2005-2赵磊  阅读(25)  评论(0)    收藏  举报