zoukankan      html  css  js  c++  java
  • Poj2656(水题)

    一、Description

    Jinjin is a junior school student. Besides the classes in school, Jinjin's mother also arranges some supplementary classes for her. However, if Jinjin studies for more than eight hours a day, she will be unhappy on that day. On any day she gets unhappy, the more time she studies, the unhappier she will be. Now we got Jinjin's class schedule for the next several days and your task is to find out whether she will be unhappy on these days; if she will be unhappy, on which day she will be the unhappiest.

    Input

    There may be several test cases. In the first line of each test case, there is an integer N (1 <= N <= 7), which represents the number of days you should analyze. Then there comes N lines, each contains two non-negative integers (each smaller than 10). The first integer represents how many hours Jinjin studies at school on the day, and the second represents how many hours she studies in the supplementary classes on the same day.

    A case with N = 0 indicates the end of the input, and this case should not be processed.

    Output

    For each test case, output a line contains a single integer. If Jinjin will always be happy, the integer should be 0; otherwise, the integer should be a positive integer K, which means that Jinjin will be the unhappiest on the K-th day. If the unhappiest day is not unique, just output the earliest one among these unhappiest days.
    二、题目分析
            水题,只是做日常工作记录。
    三、Java代码
    import java.util.Scanner;
    
    
     public class Main {
    	 
         public static void main(String[] args) {
        	 Scanner cin=new Scanner(System.in);
        	 int n;
        	 int [][] arr;
        	 while((n=cin.nextInt())!=0){
        		 int sum=0;
        		 int day=0;
        		 arr=new int [n][2];
        		 for(int i=0;i<n;i++){
        			 for(int j=0;j<2;j++){
        				arr[i][j]=cin.nextInt(); 
        			 }
        			 if((arr[i][0]+arr[i][1])>sum){
        				 sum=(arr[i][0]+arr[i][1]);
        				 day=i+1;
        			 }
        		 }
        		 if(sum > 8){
        			 System.out.println(day);
        		 }else{
        			 System.out.println(0);
        		 }
        	 }
         } 
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    django页面分类和继承
    django前端从数据库获取请求参数
    pycharm配置django工程
    django 应用各个py文件代码
    CF. 1428G2. Lucky Numbers(背包DP 二进制优化 贪心)
    HDU. 6566. The Hanged Man(树形背包DP DFS序 重链剖分)
    小米邀请赛 决赛. B. Rikka with Maximum Segment Sum(分治 决策单调性)
    区间树 学习笔记
    CF GYM. 102861M. Machine Gun(主席树)
    2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) (B, D, G, H)
  • 原文地址:https://www.cnblogs.com/AndyDai/p/4734197.html
Copyright © 2011-2022 走看看