您的位置:首页 > 游戏 > 游戏 > 成都最新的防疫通告今天_网页qq登陆首页_谷歌官网下载app_手机网站建设公司

成都最新的防疫通告今天_网页qq登陆首页_谷歌官网下载app_手机网站建设公司

2024/12/27 5:04:32 来源:https://blog.csdn.net/qq_48566899/article/details/144021420  浏览:    关键词:成都最新的防疫通告今天_网页qq登陆首页_谷歌官网下载app_手机网站建设公司
成都最新的防疫通告今天_网页qq登陆首页_谷歌官网下载app_手机网站建设公司

在这里插入图片描述

python

def read_log(filename):log = []with open(filename, 'r') as file:for line in file:correct_char, input_char, timestamp = line.split()log.append((correct_char, input_char, int(timestamp)))return logdef longest_combo(log):if len(log) <= 1:return len(log)max_combo = 1current_combo = 1for i in range(1, len(log)):if log[i][1] == log[i][0] and log[i][2] - log[i - 1][2] <= 1000:current_combo += 1if current_combo > max_combo:max_combo = current_comboelse:current_combo = 1return max_comboif __name__ == "__main__":filename = "log.txt"log = read_log(filename)result = longest_combo(log)print(result)

c

#include <stdio.h>
#include <stdlib.h>// 定义记录结构体
typedef struct {char correct_char;char input_char;long long timestamp;
} LogEntry;// 读取日志文件
int read_log(const char *filename, LogEntry *log, int *n) {FILE *file = fopen(filename, "r");if (file == NULL) {return -1;}int count = 0;while (fscanf(file, "%c %c %lld\n", &log[count].correct_char, &log[count].input_char, &log[count].timestamp) == 3) {count++;}fclose(file);*n = count;return 0;
}// 计算最长连击
int longest_combo(LogEntry *log, int n) {if (n <= 1) {return n;}int max_combo = 1;int current_combo = 1;for (int i = 1; i < n; i++) {if (log[i].input_char == log[i].correct_char && log[i].timestamp - log[i - 1].timestamp <= 1000) {current_combo++;if (current_combo > max_combo) {max_combo = current_combo;}} else {current_combo = 1;}}return max_combo;
}int main() {const char *filename = "log.txt";LogEntry log[10000]; // 假设最多有10000条记录int n;if (read_log(filename, log, &n) != 0) {fprintf(stderr, "Error reading log file.\n");return 1;}int result = longest_combo(log, n);printf("%d\n", result);return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com