题目描述:
题目链接:https://www.luogu.com.cn/problem/P1424
代码实例:
一开始想的比较复杂,先展示比较复杂的
方法一:
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();//表示从周x算起
int n = scanner.nextInt();//经过n天
int sum = 0;
for (int i = 1; i <= 7; i++) {
if(x==i) {
if(n-(7-x+1)<=5) {
sum = ((5-i)+1)*250+250*(n-(7-x+1));
}else{
if((n-(7-x+1))%7>=1 && (n-(7-x+1))%7<=5) {
sum = ((5-i)+1)*250+(n-(7-x+1))/7*5*250+(n-(7-x+1))%7*250;
}else if((n-(7-x+1))%7>5 && (n-(7-x+1))%7<=7 || (n-(7-x+1))%7==0){
sum = ((5-i)+1)*250+(n-(7-x+1))/7*5*250;
}
}
}
if(i==7 && x==7) {
if((n-1)%7<=5) {
sum = ((n-1)/7)*5*250+((n-1)%7)*250;
}else if((n-1)%7==0) {
sum = ((n-1)/7)*5*250;
}else if((n-1)%7<=5) {
sum = ((n-1)/7)*5*250+(n-1)%7*250;
}else if((n-1)%7>5 && (n-1)%7<=7 ) {
sum = ((n-1)/7)*5*250+5*250;
}
}
if(i==6 && x==6) {
if((n-2)/7<=5) {
sum = ((n-2)/7)*5*250+((n-2)/7)*250;
}else {
sum = ((n-2)/7)*5*250+5*250;
}
}
}
System.out.println(sum);
scanner.close();
}
}
简便的
方法二:
public class Main{
public static void main(String args[]) {
Scanner scanner = new Scanner (System.in);
int xingqi = scanner.nextInt();
int day = scanner.nextInt();
int sum = 0;
for (int i = 0; i < day; i++) {
if(xingqi!=6 && xingqi!=7) {
sum += 250;
}
if(xingqi==7) {
xingqi = 1;
}else {
xingqi++;
}
}
System.out.println(sum);
scanner.close();
}
}
lovuc
发布了84 篇原创文章 · 获赞 33 · 访问量 1万+
私信
关注