POJ——1006( Biorhythms)问题
程序代码如下:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner get=new Scanner(System.in);
int p;//身体
int e;//情感
int i;//智力
int d;//起始日期
int t=1;//t表示case
int total;//下次重逢时总日期
while(get.hasNext()) {
p=get.nextInt();//身体
e=get.nextInt();//情感
i=get.nextInt();//智力
d=get.nextInt();//起始日期
if(p==-1&&e==-1&&i==-1&&d==-1) {
break;
}
for(int j=1;j<=28*33;j++) {
for(int k=1;k<=23*33;k++) {
for(int y=1;y<=23*28;y++) {
if((p+23*j)==(e+28*k)&&(p+23*j)==(i+33*y)) {
total=p+23*j;
if(total==d) {
continue;
}else {
System.out.println("Case "+t+": the next triple peak occurs in "+(total-d)+" days.");
}
}
}
}
}
t++;
}
get.close();
}
}
运行结果如下: