注意最后一页可能不够m个

数据分页说明

http://www.nowcoder.com/questionTerminal/b6c448328c4f486d8cce39245889cdfe

注意最后一页可能不够m个就行了:

import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        for(int i = 0; i < n; ++i) v[i] = sc.nextInt();
        int r = sc.nextInt(), m = sc.nextInt();
        if(r*m >= n){
            System.out.println("超过分页范围");
            return;
        }
        for(int i = r*m; i < Math.min(n, r*m + m); ++i){    //最后一页可能不够m个
            System.out.println(v[i]);
        }
    }
}
全部评论

相关推荐

昨天 16:00
门头沟学院 Java
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务