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;
}
相关推荐
chushiyunen5 小时前
欧洲地理笔记
笔记
吃着火锅x唱着歌5 小时前
Effective C++ 学习笔记 条款43 学习处理模板化基类内的名称
c++·笔记·学习
GGMM78911 小时前
VX4B600100 控制板全解析:施耐德 ATV630 变频器核心控制单元详解
笔记·变频器·变频器维修
kdxiaojie13 小时前
Linux USB驱动阅读笔记(1)
linux·笔记·学习·usb
半生过往13 小时前
前端学 Java 课程笔记
java·前端·笔记
九硕智慧建筑一体化厂家13 小时前
楼宇自控|智慧建筑核心引擎!楼宇自控系统,赋能建筑高效低碳运维
运维·人工智能·笔记·智慧城市
GGMM78914 小时前
施耐德 VX5A1HC90110(VX5A1HD9011)ATV61/ATV71 90‑110KW 电源驱动板详解
笔记·变频器·变频器维修
Wang's Blog15 小时前
PostgreSQL笔记48: 全文检索与向量检索的对比与混合检索实践
笔记·postgresql·全文检索
liuyicenysabel16 小时前
Flask 个人站 iProfile 上线笔记(k3s + Nginx + Let‘s Encrypt)
笔记·nginx·flask
深蓝海拓16 小时前
基于QtPy (PySide6) 的PLC-HMI工程项目(十五)后续完善和改进:PLC端数据解析的防粘包、残包、废包、拆包
笔记·学习·plc