定义double类型时,输出用%f
pow()函数使用时是: double Math.pow(double x,double y);
实验一(2)
AC - 蝴蝶效应
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int n,a,b,c,d;
long f[]=new long [10005];
n=sc.nextInt();
f[0]=sc.nextInt();
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
d=sc.nextInt();
for(int i=1;i<=n;i++)
{
f[i]=(a*f[Math.max(0, i-b)]+c*f[Math.max(0, i-d)])%1000000007;
}
System.out.printf("%d\n",f[n]);
}
}
}
X - C语言实验——圆柱体计算
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner m=new Scanner(System.in);
double pi=3.1415926;
int x=m.nextInt();
int y=m.nextInt();
System.out.printf("%.2f %.2f %.2f %.2f\n",2*1.0*pi*x,pi*x*x*1.0,2*1.0*pi*x*y,pi*x*x*y);
}
}
Y - C语言实验——温度转换
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner m=new Scanner(System.in);
double x=m.nextDouble();
double y=5*(x*1.0-32)/9;
System.out.printf("%.2f\n",y);
}
}
Z - 火车
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner m=new Scanner(System.in);
int t=m.nextInt();
while(t>0)
{
t--;
int s=0;
int sum=0;
int n=m.nextInt();
while(n>0)
{
n--;
int a=m.nextInt();
int b=m.nextInt();
s=s-a+b;
if(sum<s) sum=s;
}
System.out.printf("%d\n\n",sum);
}
}
}
AA - 压岁钱
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner m=new Scanner(System.in);
int n=m.nextInt();
while(n>0)
{
n--;
int x=m.nextInt();
if(1000000%x==0) System.out.printf("%d\n",1000000/x);
else System.out.printf("No\n");
}
}
}
AB - 直角坐标系
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner m=new Scanner(System.in);
while(m.hasNext())
{
int x=m.nextInt();
int y=m.nextInt();
if(x>0&&y>0) System.out.printf("1\n");
else if(x<0&&y>0) System.out.printf("2\n");
else if(x<0&&y<0) System.out.printf("3\n");
else System.out.printf("4\n");
}
}
}
AD - 数字和
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int t = sc.nextInt();
int s = 0;
while (t > 0) {
t--;
int x = sc.nextInt();
if (x % 2 != 0)
s = s + x;
}
System.out.printf("%d\n", s);
}
}
}
AE - 得分
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner (System.in);
while(sc.hasNext())
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
System.out.printf("%d\n",a*3+b*2+c);
}
}
}
AF - 神奇的细胞
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double x=sc.nextInt();
System.out.printf("%.0f\n",Math.pow(2,x-1));
}
}
AG - 学区房问题
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int s1=sc.nextInt();
int s2=sc.nextInt();
int t1=sc.nextInt();
int t2=sc.nextInt();
int s=s2*t2-s1*t1;
if(s<=0) System.out.printf("0\n");
else System.out.printf("%d\n",s);
}
}
}
AH - 整除
最小公倍数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int n=sc.nextInt();
int k=n/5+n/6+n/8-n/5/6-n/5/8-n/6/4+n/120;
System.out.printf("%d\n",k);
}
}
}
AI - 洗衣服
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int l=sc.nextInt();
int w=sc.nextInt();
System.out.printf("%d\n",l/w);
}
}
}
AJ - 分段函数求值
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
double y;
double x=sc.nextDouble();
if(x<0) y=-x;
else if(x>0) y=Math.pow(x, 2)+1;
else y=100;
System.out.printf("%.1f\n",y);
}
}
}
AK - 计算球体积
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
double pi=3.1415927;
double r=sc.nextDouble();
double y=4*pi*r*r*r/3.0;
System.out.printf("%.3f\n",y);
}
}
}
AL - 优越数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int i=0;
t--;
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int av=(a+b+c)/3;
if(a>av) i++;
if(b>av) i++;
if(c>av) i++;
if(i>=2) System.out.printf("Yes\n");
else System.out.printf("No\n");
}
}
}
AM - 九九乘法表
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if(j==i) System.out.printf("%d*%d=%d",j,i,i*j);
else System.out.printf("%d*%d=%d ",j,i,i*j);
}
System.out.println();
}
}
}
}