UVA - 123 Searching Quickly

UVA - 123 Searching Quickly

题目大意:给一些要忽略的单词,这些单词以外都是关键字,然后给你若干个标题。要你以这些关键字进行排序(当一个标题内存在多个关键字要以每个关键字都参与排序),最后输出。
解题思路: 定义一个结构体用来存放单个单词和他所在的标题位置,然后将这个结构体按字典序排序,相同时按标题从小到大排序即可。将标题的单个单词抓取到结构体即可,然后就是输出时把单词大写输出就好

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
struct B{
    char a[1000];
    int b;
}b[1000];
int cmp (const void *a, const void *b) {
    if ( strcmp((*(B *)a).a,(*(B*)b).a) != 0 ) 
        return strcmp((*(B *)a).a,(*(B*)b).a);
    else
        return ( (*(B *)a).b - (*(B *)b).b);
}
int main() {
    char c[1000][1000];
    char a[1000][1000];
    char d[1000][1000];
    int flag;
    scanf ("%s", c[0]);
    int tt;
    for (int i = 1; strcmp(c[i-1], "::") != 0; i++) {
        scanf("%s", c[i]);
        tt = i;
    }
    int t = 0;
    int s = 0;
    getchar();
    while (gets(a[t])) {
        for (int i = 0; i < strlen(a[t]); i++)
            if (a[t][i] >= 'A' && a[t][i] <= 'Z')
                a[t][i] += 32;
        int cc = 0;
        for (int i = 0; i < strlen(a[t]); i++) {
            if (a[t][i] == ' ') {
                b[s].b = t;
                s++;
                cc = 0;
                continue;
            }
            b[s].a[cc] = a[t][i];
            cc++;
            if ( i == (strlen(a[t]) - 1) ) {
                b[s].b = t;
                s++;
            }
        }
        t++;
    }
    qsort(b, s, sizeof(b[0]), cmp);
    int aa[10000][100];
    memset(aa, 1, sizeof(aa));
    for (int i = 0; i < s; i++) {
        flag = 1;
        for (int j = 0; j < tt ; j++) {
            if (strcmp(b[i].a, c[j]) == 0)
                flag = 0;
        }
        if (flag ) {
            int ccc = b[i].b;
            strcpy(d[ccc], a[ccc]);
            for (int j = 0; j < strlen(a[ccc]); j++) {
                if (a[ccc][j] == b[i].a[0] && aa[ccc][j]) {
                    for (int k = 0; k < strlen(b[i].a); k++) {
                        flag = 0;
                        if (a[ccc][j+k] == b[i].a[k])
                            flag = 1;
                        else break;
                        if ( k == strlen (b[i].a) - 1 )
                            if (a[ccc][j+k+1] <= 'z' && a[ccc][j+k+1] >= 'a')
                                flag = 0;

                    }
                    if (flag && aa[ccc][j]) {
                        for (int k = 0; k < strlen(b[i].a); k++) {
                            d[ccc][j] -= 32;
                            aa[ccc][j] = 0;
                            j++;

                        }
                        j--;
                        break;
                    }
                }
            }
            printf("%s\n", d[ccc]);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR: Command errored out with exit status 1: command: 'D:\Python\python.exe' 'D:\Python\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\ASUS\AppData\Local\Temp\tmphrctoh63' cwd: C:\Users\ASUS\AppData\Local\Temp\pip-install-bpjr7cw0\opencv-python Complete output (323 lines): -------------------------------------------------------------------------------- -- Trying 'Ninja (Visual Studio 17 2022 x64 v143)' generator -------------------------------- --------------------------- ---------------------- ----------------- ------------ ------- -- Not searching for unused variables given on the command line. CMake Error at CMakeLists.txt:2 (PROJECT): Generator Ninja does not support platform specification, but platform x64 was specified. -- Configuring incomplete, errors occurred! -- ------- ------------ ----------------- ---------------------- --------------------------- -------------------------------- -- Trying 'Ninja (Visual Studio 17 2022 x64 v143)' generator - failure -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Trying 'Visual Studio 17 2022 x64 v143' generator -------------------------------- --------------------------- ---------------------- ----------------- ------------ ------- -- Not searching for unused variables given on the command line. CMake Error at CMakeLists.txt:2 (PROJECT): Generator Visual Studio 17 2022 could not find any instance of Visual Studio. -- Configuring incomplete, errors occurred!
最新发布
07-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值