网易互娱5道编程题第三题,输入怎么搞得,输入弄了很久

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
class DataType {
    long time;
    int flow;
    public DataType(long time,int flow) {
        this.time = time;
        this.flow = flow;
    }
}
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        int N = Integer.parseInt(br.readLine());
        int index = 0;
        List<DataType> list = new ArrayList<DataType>();
        while (index < N) {//注意while处理多个case
            String str = br.readLine();
            SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            try {
                Date dt2 = sdf.parse(str.substring(0, 19));
                int flow = Integer.parseInt(str.substring(20));
                DataType dataType = new DataType(dt2.getTime() / 1000, flow);
                list.add(dataType);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            ++index;
        }
        int M = Integer.parseInt(br.readLine());
        index = 0;
        while (index < M) {//注意while处理多个case
            String str = br.readLine();
            System.out.println("in");
            SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            try {
                Date dt2 = sdf.parse(str.substring(0,19));
                long time1 = dt2.getTime() / 1000;
                Date dt3 = sdf.parse(str.substring(21));
                long time2 = dt3.getTime() / 1000;
                int sum = 0;
                for(int i = 0;i < list.size(); ++i) {
                    if(list.get(i).time >= time1 && list.get(i).time <= time2) {
                        sum += list.get(i).flow;
                    }
                }
                
                System.out.println(sum);
                
            } catch (ParseException e) {
                e.printStackTrace();
            }
            ++index;
        }
        
    }
}

大神帮我看看,最后一个用例就是没输出

5

02/12/2016 00:00:00 10

02/18/2016 12:00:00 45

02/18/2016 23:59:59 8

02/19/2016 08:00:15 20

02/22/2016 13:00:00 31

4

01/01/2014 00:00:00 01/01/2017 00:00:00

11/11/2016 11:11:11 02/14/2017 00:05:20

02/12/2016 00:00:00 02/18/2016 23:00:00

02/18/2016 12:00:00 02/18/2016 12:00:00 <- 这个总是没有输出


全部评论
#include<iostream> using namespace std; #include<string> #include<vector> #include<math.h> string str = ""; string str_min = ""; string str_max = ""; long int liuliang[10000]; void  chuli(string str1,string str5) {     int j;     for(j = 6; j <=9;j++)         str +=str1[j];     for(j = 0; j <= 1;j++)         str += str1[j];     for(j = 3 ; j <= 4; j++)         str += str1[j];     for(j = 0; j <= 1; j++)         str += str5[j];     for(j = 3; j <= 4;j++)         str += str5[j];     for(j = 6; j <= 7; j++)         str += str5[j]; } void chuli1(string str3,string str6,string str7,string str8) {     int j;     for(j = 6; j <=9; j ++)         str_min +=str3[j];     for(j = 0; j  <=1 ; j++)         str_min += str3[j];     for(j = 3 ; j <= 4; j ++)         str_min += str3[j];     for( j = 0; j <= 1 ; j++)         str_min += str6[j];     for(j = 3; j <= 4; j ++)         str_min += str6[j];     for(j = 6; j <= 7; j ++)         str_min += str6[j];     for(j = 6; j <= 9; j ++)         str_max += str7[j];     for(j = 0; j <= 1; j ++)         str_max += str7[j];     for(j = 3;j <= 4; j ++)         str_max += str7[j];     for(j = 0; j <= 1;j++)         str_max += str8[j];     for(j = 3; j <= 4; j++)         str_max += str8[j];     for(j = 6; j <= 7;j++)         str_max += str8[j];      }           int main() {     long int n;     cin >> n;     long int i ;     long int num = 0;     string str2;     string str_10,str_20,str_30,str_40;     vector<string> v;     int result = 0;     for(i = 0 ; i < n ; i ++)     {         cin >> str2;         cin >> str_10;         cin >> num;         chuli(str2,str_10);         v.push_back(str);     //    cout << str;         liuliang[i] = num;         str = "";         num = 0;     }     int m;     cin >> m;     int j;     for(i = 0 ; i < m ; i ++)     {         cin >> str_10;         cin >> str_20;         cin >> str_30;         cin >> str_40;         chuli1(str_10,str_20,str_30,str_40);     //    cout << str_max << endl; //        cout << endl; //        cout << str_min << endl; //        cout << str_max;         for(j = 0 ; j < n;j++)         {             if((str_min <= v[j])&&(str_max >= v[j]))             {                 result += liuliang[j];             //    cout << 444444 << endl;             }         }         cout << result << endl;         result = 0;         str_min = "";         str_max = "";              }     return 0;           } 刚刚笔试的时候把月/日/年写成了日/月/年。。。好心塞,难怪一直是0%了,现在把日月年改过来了,运行例子是正确的。
点赞 回复 分享
发布于 2017-09-16 22:58
过了70
点赞 回复 分享
发布于 2017-09-16 21:46
我这个通过10% 我在本地测试总是最后一个用例没有输出
点赞 回复 分享
发布于 2017-09-16 21:42
我有输出,样例过了但是ac率为0
点赞 回复 分享
发布于 2017-09-16 21:41
是不是格式不准确。。。。我也是,改来改去改的烦死了
点赞 回复 分享
发布于 2017-09-16 21:41

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务