课堂小测三
终于把补丁打好了,虽然说参考了一下他们的,过程也有些小曲折,但是终终终终终终终终终终终终终终于写完了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 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); } } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术