CCF20240302——相似度计算

CCF20240302------相似度计算



代码如下:

javascript 复制代码
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX_WORD_LEN 100
#define MAX_WORDS 10000

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    char words1[MAX_WORDS][MAX_WORD_LEN];
    char words2[MAX_WORDS][MAX_WORD_LEN];
    char temp_word[MAX_WORD_LEN];

    int size1 = 0, size2 = 0;

    // 读取第一篇文章的单词
    for (int i = 0; i < n; i++) {
        scanf("%s", temp_word);
   
        // 转换为小写
        for (int j = 0; temp_word[j]; j++) {
            if (temp_word[j] >= 'A' && temp_word[j] <= 'Z') {
                temp_word[j] += 'a' - 'A';
            }
        }

        // 检查是否已经在words1中
        int found = 0;
        for (int j = 0; j < size1; j++) {
            if (strcmp(temp_word, words1[j]) == 0) {
                found = 1;
                break;
            }
        }
        if (!found) {
            strcpy(words1[size1++], temp_word);
        }
    }

    // 读取第二篇文章的单词
    for (int i = 0; i < m; i++) {
        scanf("%s", temp_word);

        // 转换为小写
        for (int j = 0; temp_word[j]; j++) {
            if (temp_word[j] >= 'A' && temp_word[j] <= 'Z') {
                temp_word[j] += 'a' - 'A';
            }
        }

        // 检查是否已经在words2中
        int found = 0;
        for (int j = 0; j < size2; j++) {
            if (strcmp(temp_word, words2[j]) == 0) {
                found = 1;
                break;
            }
        }
        if (!found) {
            strcpy(words2[size2++], temp_word);
        }
    }

    int intersection_count = 0;
    int union_count = size1;

    // 计算交集
    for (int i = 0; i < size2; i++) {
        int found = 0;
        for (int j = 0; j < size1; j++) {
            if (strcmp(words2[i], words1[j]) == 0) {
                found = 1;
                break;
            }
        }
        if (found) {
            intersection_count++;
        } else {
            union_count++;
        }
    }

    printf("%d\n", intersection_count);
    printf("%d\n", union_count);

    return 0;
}
相关推荐
sealaugh322 小时前
aws(学习笔记第四十八课) appsync-graphql-dynamodb
笔记·学习·aws
freexyn4 小时前
Matlab自学笔记六十一:快速上手解方程
数据结构·笔记·matlab
很小心的小新5 小时前
12、jvm运行期优化
java·开发语言·jvm·笔记
寻丶幽风7 小时前
论文阅读笔记——NoPoSplat
论文阅读·笔记·三维重建·3dgs·相机位姿·dustr
西岭千秋雪_9 小时前
Redis缓存架构实战
java·redis·笔记·学习·缓存·架构
XvnNing9 小时前
【Verilog硬件语言学习笔记4】FPGA串口通信
笔记·学习·fpga开发
海棠蚀omo9 小时前
C++笔记-位图和布隆过滤器
开发语言·c++·笔记
大胡子大叔10 小时前
webrtc-streamer视频流播放(rstp协议h264笔记)
笔记·webrtc·rtsp·webrtc-streamer
山野万里__11 小时前
C++与Java内存共享技术:跨平台与跨语言实现指南
android·java·c++·笔记
寻丶幽风13 小时前
论文阅读笔记——VGGT: Visual Geometry Grounded Transformer
论文阅读·笔记·transformer·三维重建·3dgs·vggt