当前位置:首页 > 蓝桥杯 练习系统 算法提高答案Java
ADV-127 日期计算
import java.util.Scanner;
class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int y = input.nextInt(); int m = input.nextInt(); int d = input.nextInt(); int i, j, k, s1 = 0, s2 = 0, x = 0, s, z = 0; for (i = 1; i < 2011; i++) { s1 = s1 + 365; if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) { s1++; } } s1 = s1 + 315; for (j = 1; j < y; j++) { s2 = s2 + 365; if ((j % 4 == 0 && j % 100 != 0) || (j % 400 == 0)) { s2++; } } for (i = 1; i < m; i++) { if(i==1) s2=s2+31; if(i==2) {s2=s2+28; if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {s2++;} } if(i==3) s2=s2+31; if(i==4) s2=s2+30; if(i==5) s2=s2+31; if(i==6) s2=s2+30; if(i==7) s2=s2+31;
if(i==8) s2=s2+31; if(i==9) s2=s2+30; if(i==10) s2=s2+31; if(i==11) s2=s2+30;
}
s2 = s2 + d;
s = s2 - s1; if (s < 0) { s = 0 - s; z = 1; }
if (z == 0) { x = (s % 7) + 5; if (s % 7 > 2) { x = x % 7; }
} else if (z == 1) { x = 5 - (s % 7); if (s % 7 == 5) x = 7; if (s % 7 == 6) x = 6; }
System.out.println(x);
}
}
ADV-123
import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); double[][] dp=new double[110][11000];
概率计算
}
}
int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int x=sc.nextInt();
double p=1.0/(b-a+1); for(int i=1;i<=n;i++){ for(int j=a*i;j<=b*i&&j<=x;j++){ if(i==1) { dp[i][j]=p; }else{ double pp=0; for(int z=a;z<=b;z++){ if(j>=z) pp+=dp[i-1][j-z]*p; } dp[i][j]=pp; } } }
System.err.printf(\
ADV-120 6-17复数四则运算
import java.util.Scanner;
public class Main{ /** * @author linfan */ public static void main(String[] args) { Scanner sc=new Scanner(System.in); String[] ss=sc.nextLine().split(\ int a=Integer.parseInt(ss[0]); int b=Integer.parseInt(ss[1]); int c=Integer.parseInt(ss[3]); int d=Integer.parseInt(ss[4]); char ch=ss[2].charAt(0); int p,q; String s=\ switch(ch){ case '+': p=a+c;q=b+d; if(p!=0)s+=p;
}
}
if(q>0) s+=\ if(q<0) s+=q+\ break; case '-': p=a-c;q=b-d; if(p!=0)s+=p; if(q>0) s+=\ if(q<0) s+=q+\ break; case '*': p=a*c-b*d;q=b*c+a*d; if(p!=0)s+=p; if(q>0) s+=\ if(q<0) s+=q+\ break; case '/': int m=c*c+d*d; if(m==0){ s=\ } double p1=(a*c+b*d)*1.0/m; double q1=(b*c-a*d)*1.0/m; if(p1!=0){ if((a*c+b*d)%m==0)s+=(int)p1; else s+=p1; } if(q1>0){ if((b*c-a*d)%m==0)s+=\ else s+=\ } if(q1<0){ if((b*c-a*d)%m==0)s+=(int)q1+\ else s+=q1+\ } break; default:break; }
System.out.println(s);
ADV-112 c++_ch02_01
public class Main { public static void main(String[] args) { System.out.println((int)'A'); System.out.println((int)'E');
共分享92篇相关文档