UVA-409 Excuses, Excuses!

UVA-409 Excuses, Excuses!

题目大意:先输入 x 个单词,再输入 y 个句子。统计 y 个句子中哪个含有最多单词,输出含有最多单词的句子。若相等,则一同输出。

Sample Input

5 3
dog
ate
homework
canary
died
My dog ate my homework.
Can you believe my dog died after eating my canary… AND MY HOMEWORK?
This excuse is so good that it contain 0 keywords.
6 5
superhighway
crazy
thermonuclear
bedroom
war
building
I am having a superhighway built in my bedroom.
I am actually crazy.
1234567890…..,,,,,0987654321?????!!!!!!
There was a thermonuclear war!
I ate my dog, my canary, and my homework … note outdated keywords?

Sample Output

Excuse Set #1
Can you believe my dog died after eating my canary… AND MY HOMEWORK?

Excuse Set #2
I am having a superhighway built in my bedroom.
There was a thermonuclear war!

解题思路:输入,注意将大写字母转化为小写字母,将单词逐个比较,累计求最大的,输出。

//UVA-409 Excuses, Excuses!
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n,m,value = 1;
char word[100][100];
char str1[100][100];
char str[100][100];
int numb[100];
int num(char str[100]) {
    int nn = strlen(str);
    int j = 0;
    int number = 0;
    char s[100];
    for (int i = 0; i < nn; i++) {
        if (!(str[i] >= 'a' && str[i] <= 'z' || str[i] >='A' && str[i] <= 'Z')) {
            s[j] = '\0';
            for (int j = 0; j < n; j++) {
                if (strcmp(s,word[j]) == 0)
                    number++;
            }
            j = 0;
            continue;
        }
        s[j] = str[i];
        j++;
    }
    return number;
}
int main () {
    while (scanf ("%d %d",&n,&m) != EOF) {
        getchar();
        for (int i = 0; i < n; i++) {
            gets(word[i]);
            int ss =strlen (word[i]);
            for (int j = 0; j < ss; j++) {
                if (word [i][j] >= 'A' && word [i][j] <= 'Z')
                    word[i][j] = word[i][j] + 'a' - 'A';
            }
        }
        int i,j,k;
        for (i = 0; i < m; i++) {
            gets(str1[i]);
            int ll = strlen(str1[i]);
            for (j = 0; j < ll; j++)
                str[i][j] = str1[i][j];
            str[i][j] = '\0';
            for (k = 0; k < ll; k++)
                if (str[i][k] >= 'A' && str[i][k] <= 'Z')
                    str[i][k] = str[i][k] + 'a' - 'A';
            numb[i] = num(str[i]);
        }
        printf("Excuse Set #%d\n",value++);
        int max = 0, h;
        for ( h = 0; h < m; h++) {
            if (numb[h] > max)
                max = numb[h];
        }
        for ( h = 0; h < m; h++) {
            if (numb[h] == max) {
                puts(str1[h]);
            }
        }
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值