資源簡介
輸入中,包含且僅包含一行,表示一個表達式。
關于輸出,首先程序需要對輸入數據的合法性進行判定
- 如果是一組合法的輸入數據(即符合上述的表達式基本規則),則應當輸出一行,表示求出的導函數。格式同樣需要滿足上述的表達式基本格式規則。
- 如果是一組不合法的輸入數據,則應當輸出一行`WRONG FORMAT!`

代碼片段和文件信息
import?java.math.BigInteger;
import?java.util.ArrayList;
import?java.util.Scanner;
import?java.util.regex.Pattern;
public?class?Main?{
????private?ArrayList?polyList?=?new?ArrayList<>();
????private?static?final?BigInteger?MINUXONE?=?BigInteger.valueOf(-1);
????private?void?parsePoly(String[]?polyArr)?{
????????for?(String?str?:?polyArr)?{
????????????if?(str.isEmpty())?{
????????????????continue;
????????????}?else?if?(!Pattern.matches(“.*x\\^.*“?str))?{
????????????????polyList.add(new?Poly(str?“0“));
????????????}?else?{
????????????????String[]?temp?=?str.split(“\\*x\\^“);
????????????????polyList.add(new?Poly(temp[0]?temp[1]));
????????????}
????????}
????}
????private?void?computePoly()?{
????????for?(int?i?=?0;?i?????????????for?(int?j?=?i?+?1;?j?????????????????if?(polyList.get(i).getDeg().equals(polyList.get(j).getDeg())
????????????????????????&&?!polyList.get(j).isRepeat())?{
????????????????????polyList.get(i).addTerm(polyList.get(j).getTerm());
????????????????????polyList.get(j).setRepeat(true);
????????????????}
????????????}
????????????polyList.get(i).diff();
????????}
????}
????private?void?output()?{
????????BigInteger?constant?=?BigInteger.ZERO;
????????boolean?firstOut?=?true;
????????for?(Poly?p?:?polyList)?{
????????????if?(p.isRepeat())?{
????????????????continue;
????????????}?else?if?(p.isCons())?{
????????????????constant?=?p.getTerm();
????????????}?else?if?(firstOut)?{
????????????????if?(p.getTerm().compareTo(BigInteger.ONE)?==?0)?{
????????????????????System.out.print(“x“);
????????????????}?else?if?(p.getTerm().compareTo(MINUXONE)?==?0)?{
????????????????????System.out.print(“-x“);
????????????????}?else?if?(p.getTerm().compareTo(BigInteger.ZERO)?>?0)?{
????????????????????System.out.print(p.getTerm()?+?“*x“);
????????????????}?else?{
????????????????????System.out.print(p.getTerm()?+?“*x“);
????????????????}
????????????????firstOut?=?false;
????????????}?else?if?(p.getTerm().compareTo(BigInteger.ONE)?==?0)?{
????????????????System.out.print(“+x“);
????????????}?else?if?(p.getTerm().compareTo(MINUXONE)?==?0)?{
????????????????System.out.print(“-x“);
????????????}?else?if?(p.getTerm().compareTo(BigInteger.ZERO)?>?0)?{
????????????????System.out.print(“+“?+?p.getTerm()?+?“*x“);
????????????}?else?{
????????????????System.out.print(p.getTerm()?+?“*x“);
????????????}
????????????if?(p.getDeg().compareTo(BigInteger.ONE)?!=?0
????????????????????&&?p.getDeg().compareTo(BigInteger.ZERO)?!=?0)?{
????????????????System.out.print(“^“?+?p.getDeg());
????????????}
????????}
????????if?(constant.compareTo(BigInteger.ZERO)?>=?0)?{
????????????if?(firstOut)?{
????????????????System.out.println(constant);
????????????}?else?if?(constant.compareTo(BigInteger.ZERO)?>?0)?{
????????????????System.out.println(“+“?+?constant);
????????????}
????????}?else?if?(constant.compareTo(BigInteger.ZERO)?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9637??2019-03-01?20:50??第一次作業指導書.md
?????文件???????3478??2019-03-29?19:34??src\Main.java
?????文件???????1518??2019-03-05?09:12??src\Poly.java
?????文件???????3152??2019-03-05?17:25??src\StringChecker.java
?????目錄??????????0??2019-03-29?19:34??src
-----------?---------??----------?-----??----
????????????????17785????????????????????5
- 上一篇:基于Java打磚塊小游戲
- 下一篇:Android模擬手機QQ登錄和主界面.zip
評論
共有 條評論