练习题02-01

import java.util.*;

public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String input = sc.nextLine();
String[] str=input.split(";");
int x = 0,y = 0;
for(int i = 0;i < str.length;i++){
if(correctCoordinate(str[i])){
if(str[i].charAt(0)‘A’){
x = x-Integer.parseInt(str[i].substring(1));
}
else if(str[i].charAt(0)
‘D’){
x = x+Integer.parseInt(str[i].substring(1));
}
else if(str[i].charAt(0)‘W’){
y = y+Integer.parseInt(str[i].substring(1));
}
else if(str[i].charAt(0)
‘S’){
y = y-Integer.parseInt(str[i].substring(1));
}
}
}
System.out.println(x+","+y);
}
}

public static boolean correctCoordinate(String s){//判斷是否合法有效
    int n = s.length();
    if(n <= 3 && n>1){
        if(s.charAt(0)=='A'||s.charAt(0)=='D'||s.charAt(0)=='W'||s.charAt(0)=='S'){
            if(n == 2 && Character.isDigit(s.charAt(1))){
                return true;
            }
            else if(n == 3 && Character.isDigit(s.charAt(1))
                    && Character.isDigit(s.charAt(2))){
                return true;
            }
        }
    }
    return false;
}

}

class Main1{
//最大子串的和
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0;i < n;i++){
nums[i] = sc.nextInt();
}
int max = nums[0];
int curMax = nums[0];

    for(int i = 1;i < n;i++){
        curMax = Math.max(curMax+nums[i],nums[i]);
        if(curMax > max){
            max = curMax;
        }
    }
    System.out.println(max);

}

}import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int year = sc.nextInt();
    int month = sc.nextInt();
    int day = sc.nextInt();
    int dayNum = 0;
    if (year <= 0 || month <= 0 || month > 12 || day <= 0 || day > 31) {
        System.out.println(-1);
    } else {
        for (int i = 1; i < month; i++) {
            if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                dayNum += 31;
            } else if (i == 4 || i == 6 || i == 9 || i == 11) {
                dayNum += 30;
            } else if (i == 2 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) {
                dayNum += 29;
            } else {
                dayNum += 28;
            }
        }
        System.out.println(dayNum+day);
    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值