题解 | #查询满足区间的记录#C#_O(n)_AC

查询满足区间的记录

http://www.nowcoder.com/questionTerminal/3eb4f4f8128a4372880ea73e2bbc0d7e

AC!想不出题目要求的O(logn)。反正都要读取输入,O(n)还是需要的吧。

using System;
using System.Collections;
using System.Collections.Generic;

public class Program {
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        int a = int.Parse(Console.ReadLine());
        List<int> ret = new List<int>();
        string line;
        while ((line = System.Console.ReadLine ()) != null) {
            string[] tokens = line.Split();
            int id = int.Parse(tokens[0]);
            int bt = int.Parse(tokens[1]);
            int et = int.Parse(tokens[2]);
            if (bt <= a && a <= et){
                ret.Add(id);
            }
        }
        if(ret.Count == 0){
            Console.WriteLine("null");
            return;
        }
        ret.Sort();
        foreach(var id in ret){
            Console.WriteLine(id);
        }
    }
}
全部评论

相关推荐

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

创作者周榜

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