04结对开发
代码:
package deal;
public class Calculation {
public static int deal(int a,String b,int c)
{
int x = 0;
switch(b)
{
case "+":x=a+c;break;
case "-":x=a-c;break;
case "*":x=a*c;break;
case "/":x=a/c;break;
default:x=-233333;
}
return x;
}
}
package deal;
public class data {
public String[] cha=new String[10];
public int[] num=new int[10];
public int cl=0,nl=0;
public void pupc(String x)
{cl++;
cha[cl]=x;
}
public void pupn(int x)
{nl++;
num[nl]=x;
}
public String outc()
{String x;
x=cha[cl];
cl--;
return x;
}
public int outn()
{ int x;
x=num[nl];
nl--;
return x;
}
public void deal()
{
int a,b;
String c;
b=outn();
a=outn();
c=outc();
// System.out.println(a+" "+c+" "+b);
pupn(Calculation.deal(a, c, b));
}
public String gc()
{
String s;
s=cha[cl];
return s;
}
public void show()
{int i=0;
for(i=1;i<=cl;i++)
{
System.out.println(cha[1]);
}
for(i=1;i<=nl;i++)
{
System.out.println(num[1]);
}
}
}
package deal;
public class finl {
public static int fi(data d)
{int x = 0;
int a,b;String c;
while(true)
{
if(d.nl<=1||d.cl<=0) {x=d.num[1];break;}
b=d.outn();
a=d.outn();
c=d.outc();
// System.out.println(a+" "+c+" "+b);
d.pupn(Calculation.deal(a, c, b));
// System.out.println(Calculation.deal(a, c, b));
}
return x;
}
}
package deal;
public class sd {
public static int read(String s)
{data d=new data();
int le=s.length();
String x;
int b=0,a=1,e,ea,num = 0;
while(b<le)
{a=b+1;
x=s.substring(b, a);
e=b;
if(look(x)==-1) {System.out.println("错误字符!");break; }
if(look(x)==1) {
ea=a;
while(look(x)==1) {
e++;ea++;
if(e>=le)break;
x=s.substring(e, ea);
}
a=--ea;
x=s.substring(b,a);
num=Integer.parseInt(x);
b=a;
d.pupn(num);
System.out.println(num);
}
else {
if(x.equals("=")) {break;}
else {
dc(x,d);
}
b=a;
}
}
while(d.nl>1)
{
d.deal();
}
return d.num[1];
}
public static String compare(String a,String b)
{
String s = null;int a1 = 0,b1 = 0;
if(a.equals("+")) {a1=1;}
else if(a.equals("-")) {a1=2;}
else if(a.equals("*")) {a1=3;}
else if(a.equals("/")) {a1=4;}
System.out.println(a1);
if(b.equals("+")) {b1=1;}
else if(b.equals("-")) {b1=2;}
else if(b.equals("*")) {b1=3;}
else if(b.equals("/")) {b1=4;}
if(a1>b1) {s=">";}
else if(a1<b1) {s="<";}
else {s="="; }
return s;
}
public static int look(String a)
{
if(a.equals("+")||a.equals("-")||a.equals("*")||a.equals("/")||a.equals("(")||a.equals(")")||a.equals("=")) {return 0;}
else if(a.equals("1")||a.equals("2")||a.equals("3")||a.equals("4")||a.equals("5")||a.equals("6")||a.equals("7")||a.equals("8")||a.equals("9")||a.equals("0")) return 1;
else return -1;
}
public static void dc(String x,data d)
{
String s;int a,b,c;
if(x.equals("(")) {d.pupc(x);}
else if(x.equals(")")) {
s=d.gc();
while(!s.equals("(")) {
d.deal();
s=d.gc();
}
d.outc();
}
else if(d.cl==0) {d.pupc(x);}
else if(compare(x,d.gc()).equals(">")) {d.pupc(x);}
else if(compare(x,d.gc()).equals("<")) {
s=d.outc();
b=d.outn();
a=d.outn();
c=Calculation.deal(a, x, b);
d.pupn(c);
d.pupc(x);
}
else if(compare(x,d.gc()).equals("=")) {
s=d.outc();
b=d.outn();
a=d.outn();
c=Calculation.deal(a, x, b);
d.pupn(c);
d.pupc(x);
}
}
}
package yunsuan;
import java.util.Scanner;
import deal.Calculation;
import deal.data;
import deal.finl;
import deal.sd;
public class main {
static Scanner input=new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
data d = new data();
System.out.println(sd.read("2+2/2-3*4"));
}
}
package yunsuan;
import java.util.Scanner;
public class test {
static Scanner input=new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
int[] x= {1,2,3,4,5};
int[] y={1,2,-3,-4,-5};
int[] z={6,1,2,0,5,4,1,2,0,5,4};
System.out.println(Largest(x,5));
System.out.println(Largest(y,5));
System.out.println(Largest(z,11));
}
public static int Largest(int list[],int length)
{int i,max=list[0];
for(i=0;i<=(length-1);i++)
{
if(list[i]>max)
{
max=list[i];
}
}
return max;
}
}