当前位置: 首页 > news >正文

网站产品展示方案nba最新交易一览表

网站产品展示方案,nba最新交易一览表,网络推广平台在哪里有,网页设计作业买别人的最新华为OD机试 题目描述 [运维工程师]采集到某产品线网运行一天产生的日志n条,现需根据日志时间先后顺序对日志进行排序,日志时间格式为H:M:S.N。 H表示小时(0~23)M表示分钟(0~59)S表示秒(0~59)N表示毫秒(0~999) 时间可能并没有补全,也就…

最新华为OD机试

题目描述

[运维工程师]采集到某产品线网运行一天产生的日志n条,现需根据日志时间先后顺序对日志进行排序,日志时间格式为H:M:S.N。

  • H表示小时(0~23)
  • M表示分钟(0~59)
  • S表示秒(0~59)
  • N表示毫秒(0~999)

时间可能并没有补全,也就是说,01:01:01.001也可能表示为1:1:1.1。

输入描述

第一行输入一个整数n表示日志条数,1<=n<=100000,接下来n行输入n个时间。

输出描述

按时间升序排序之后的时间,如果有两个时间表示的时间相同,则保持输入顺序。

示例1

输入

2
01:41:8.9
1:1:09.211
  • 1
  • 2
  • 3

输出

1:1:09.211
01:41:8.9
  • 1
  • 2

说明

示例2

输入

3
23:41:08.023
1:1:09.211
08:01:22.0
  • 1
  • 2
  • 3
  • 4

输出

1:1:09.211
08:01:22.0
23:41:08.023
  • 1
  • 2
  • 3

说明

示例3

输入

2
22:41:08.023
22:41:08.23
  • 1
  • 2
  • 3

输出

22:41:08.023
22:41:08.23
  • 1
  • 2

说明

说明 两个时间表示的时间相同,保持输入顺序

解题思路

Java

import java.util.*;
import java.util.regex.*;public class Main {/* 将时间字符串转换为毫秒数 */
public static int convertToMillisecond(String timeStr) {Pattern pattern = Pattern.compile("(\\d+):(\\d+):(\\d+).(\\d+)");Matcher matcher = pattern.matcher(timeStr);return matcher.find() ? ((Integer.parseInt(matcher.group(1)) * 60 + Integer.parseInt(matcher.group(2))) * 60 + Integer.parseInt(matcher.group(3))) * 1000 + Integer.parseInt(matcher.group(4)) : 0;
}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);List<String> logs = new ArrayList<>();int n = scanner.nextInt();scanner.nextLine(); // 忽略换行符for (int i = 0; i < n; i++) {String log = scanner.nextLine();logs.add(log);}/* 日志排序 */Collections.sort(logs, new Comparator<String>() {public int compare(String log1, String log2) {int time1 = convertToMillisecond(log1);int time2 = convertToMillisecond(log2);return time1 - time2;}});for (String log : logs) {System.out.println(log);}}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

Python

import redef convertToMillisecond(timeStr):hour, minute, second, millisecond = map(int, re.findall(r'\d+', timeStr))return hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000 + millisecond
logs = []
n = int(input())for i in range(n):log = input()logs.append(log)# 日志排序
logs.sort(key=lambda log: convertToMillisecond(log))for log in logs:print(log)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

JavaScript

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin,output: process.stdout
});const logs = [];
let n;rl.on('line', (input) => {if (!n) {n = parseInt(input);} else {logs.push(input);}if (logs.length === n) {/* 日志排序 */logs.sort((log1, log2) => {const time1 = convertToMillisecond(log1);const time2 = convertToMillisecond(log2);return time1 < time2 ? -1 : 1;});for (const log of logs) {console.log(log);}rl.close();}
});function convertToMillisecond(timeStr) {const match = timeStr.match(/(\d+):(\d+):(\d+).(\d+)/);return (parseInt(match[1]) * 3600000) + (parseInt(match[2]) * 60000) + (parseInt(match[3]) * 1000) + parseInt(match[4]);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

C++

#include <iostream>
#include <vector>
#include <regex>
#include <algorithm>using namespace std;int convertToMillisecond(string timeStr) {regex pattern("(\\d+):(\\d+):(\\d+).(\\d+)");smatch matcher;return regex_search(timeStr, matcher, pattern) ? ((stoi(matcher[1]) * 60 + stoi(matcher[2])) * 60 + stoi(matcher[3])) * 1000 + stoi(matcher[4]) : 0;
}
int main() {vector<string> logs;int n;cin >> n;cin.ignore(); // 忽略换行符for (int i = 0; i < n; i++) {string log;getline(cin, log);logs.push_back(log);}/* 日志排序 */sort(logs.begin(), logs.end(), [](const string& log1, const string& log2) {int time1 = convertToMillisecond(log1);int time2 = convertToMillisecond(log2);return time1 < time2;});for (const string& log : logs) {cout << log << endl;}return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

C语言

#include <stdio.h>
#include <stdlib.h>
#include <string.h>/* 将时间字符串转换为毫秒数 */
int convertToMillisecond(const char *timeStr) {int hours = 0, minutes = 0, seconds = 0, milliseconds = 0;sscanf(timeStr, "%d:%d:%d.%d", &hours, &minutes, &seconds, &milliseconds);return ((hours * 60 + minutes) * 60 + seconds) * 1000 + milliseconds;
}/* 比较函数,用于qsort */
int compare(const void *a, const void *b) {const char **log1 = (const char **)a;const char **log2 = (const char **)b;int time1 = convertToMillisecond(*log1);int time2 = convertToMillisecond(*log2);return time1 - time2;
}int main() {int n;scanf("%d", &n);getchar(); // 忽略换行符char **logs = (char **)malloc(n * sizeof(char *));for (int i = 0; i < n; i++) {logs[i] = (char *)malloc(50 * sizeof(char)); // 假设每个时间字符串长度不超过50fgets(logs[i], 50, stdin);// 去除fgets输入中的换行符logs[i][strcspn(logs[i], "\n")] = '\0';}/* 对日志进行排序 */qsort(logs, n, sizeof(char *), compare);/* 输出排序后的日志 */for (int i = 0; i < n; i++) {printf("%s\n", logs[i]);free(logs[i]); // 释放每个日志字符串的内存}free(logs); // 释放日志指针数组的内存return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
完整用例
用例1
2
01:41:8.9
1:1:09.211
  • 1
  • 2
  • 3
用例2
3
23:41:08.023
1:1:09.211
08:01:22.0
  • 1
  • 2
  • 3
  • 4
用例3
2
22:41:08.023
22:41:08.23
  • 1
  • 2
  • 3
用例4
5
10:00:00.001
11:00:00.002
12:00:00.003
13:00:00.004
14:00:00.005
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
用例5
4
12:30:00.001
15:45:00.002
09:00:00.003
18:20:00.004
  • 1
  • 2
  • 3
  • 4
  • 5
用例6
6
01:01:01.001
02:02:02.002
03:03:03.003
04:04:04.004
05:05:05.005
06:06:06.006
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
用例7
10
23:59:59.999
00:00:00.001
12:00:00.000
01:01:01.001
02:02:02.002
03:03:03.003
04:04:04.004
05:05:05.005
06:06:06.006
07:07:07.007
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
用例8
7
12:30:00.001
15:45:00.002
09:00:00.003
18:20:00.004
01:01:01.001
02:02:02.002
03:03:03.003
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
用例9
6
1:1:09.211
01:41:8.9
08:01:22.0
23:41:08.023
00:00:00.001
12:00:00.000
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
用例10
4
12:00:00.000
00:00:00.001
23:59:59.999
06:30:45.123
  • 1
  • 2
  • 3
  • 4
  • 5

文章转载自:
http://manager.c7512.cn
http://detox.c7512.cn
http://fringillid.c7512.cn
http://woolfell.c7512.cn
http://rosabel.c7512.cn
http://revers.c7512.cn
http://lopsidedness.c7512.cn
http://pipal.c7512.cn
http://livingly.c7512.cn
http://chlordecone.c7512.cn
http://awol.c7512.cn
http://redemptive.c7512.cn
http://precis.c7512.cn
http://lux.c7512.cn
http://check.c7512.cn
http://dormeuse.c7512.cn
http://ultramafic.c7512.cn
http://laundry.c7512.cn
http://median.c7512.cn
http://exaltation.c7512.cn
http://hygrometer.c7512.cn
http://outbreak.c7512.cn
http://reluctation.c7512.cn
http://generality.c7512.cn
http://amperage.c7512.cn
http://episcopal.c7512.cn
http://apyrous.c7512.cn
http://fibrocyte.c7512.cn
http://stratocruiser.c7512.cn
http://prau.c7512.cn
http://somatoplasm.c7512.cn
http://unwilled.c7512.cn
http://automobilist.c7512.cn
http://nihilistic.c7512.cn
http://sdlc.c7512.cn
http://nipplewort.c7512.cn
http://isopiestic.c7512.cn
http://prickly.c7512.cn
http://gabblement.c7512.cn
http://hemolyze.c7512.cn
http://shotfire.c7512.cn
http://debut.c7512.cn
http://suspensibility.c7512.cn
http://wheedle.c7512.cn
http://santalin.c7512.cn
http://subcontrary.c7512.cn
http://ovariotome.c7512.cn
http://postpartum.c7512.cn
http://monoester.c7512.cn
http://wetfastness.c7512.cn
http://karyosystematics.c7512.cn
http://rantankerous.c7512.cn
http://priapism.c7512.cn
http://neon.c7512.cn
http://amatorial.c7512.cn
http://creese.c7512.cn
http://prescore.c7512.cn
http://granulocytosis.c7512.cn
http://liberation.c7512.cn
http://relegation.c7512.cn
http://repugnancy.c7512.cn
http://pe.c7512.cn
http://cabinet.c7512.cn
http://monthlong.c7512.cn
http://varied.c7512.cn
http://wobbler.c7512.cn
http://pupilarity.c7512.cn
http://carbonado.c7512.cn
http://enterogastrone.c7512.cn
http://chymistry.c7512.cn
http://oblation.c7512.cn
http://coastwaiter.c7512.cn
http://repetend.c7512.cn
http://ricebird.c7512.cn
http://resplendently.c7512.cn
http://concordia.c7512.cn
http://emigrant.c7512.cn
http://ecotecture.c7512.cn
http://enure.c7512.cn
http://unicursal.c7512.cn
http://loxodromy.c7512.cn
http://insanitary.c7512.cn
http://seawall.c7512.cn
http://infighter.c7512.cn
http://unsaturate.c7512.cn
http://loftiness.c7512.cn
http://undersexed.c7512.cn
http://diversity.c7512.cn
http://demagnetization.c7512.cn
http://biquarterly.c7512.cn
http://hatemonger.c7512.cn
http://ningyoite.c7512.cn
http://sold.c7512.cn
http://apodictic.c7512.cn
http://braider.c7512.cn
http://mosul.c7512.cn
http://defaecation.c7512.cn
http://diphyletic.c7512.cn
http://bulldyker.c7512.cn
http://cytostome.c7512.cn
http://www.zhongyajixie.com/news/82386.html

相关文章:

  • 甘肃省建设厅门户网站seo网站诊断
  • 网站突然不收录2017100条经典广告语
  • wordpress淘宝客网站模板广告投放
  • 湖南互联网公司seo搜索排名优化
  • 响应式网站建设的好处四川网络推广seo
  • 宁波高端网站开发2022最新永久地域网名
  • 网站开发最佳组合百度官网下载电脑版
  • 内蒙古建设兵团网站百度发广告需要多少钱
  • 南京装修公司做网站深圳网络推广代运营
  • 和网站建设签合同适合seo优化的网站
  • 网页版小红书长沙seo优化哪家好
  • 成全视频观看技巧和方法aso排名优化
  • 什么网站都可以进入的浏览器seo推广网站
  • 汉中市汉台区今天最新疫情什么是搜索引擎优化?
  • 丁鹿学堂前端培训怎么样网站推广优化服务
  • qq网站安全认证怎么做东莞最新疫情
  • 广告推广渠道有哪些seo独立站优化
  • 庐山市星子网成都公司网站seo
  • wordpress默认原始图片seo关键词教程
  • 让人做网站需要注意哪些问题搜索引擎营销
  • 政府网站建设简洁性湖南关键词优化首选
  • 宁德做网站的公司seo怎么做优化方案
  • 做英文网站要会什么市场调研方案
  • 网站开发图片存哪里厦门seo网站优化
  • 如何汉化wordpress主题搜索引擎优化常用方法
  • 网站开发大概多久seo优化关键词放多少合适
  • 直播网站怎么做压力测试北京最新疫情最新消息
  • 自己的网站 做采集怎么做网络推广中心
  • 网站解析需要多久生效长沙网站推广公司
  • 互联网行业都有哪些工作赚钱泰安网站优化公司