The Country List

本文探讨了在处理相似国家名称识别的问题上,志愿者CC所面临的挑战。文章详细介绍了输入数据格式,即多个国家名称列表,并阐述了如何通过比较每个名称的长度及相同位置字母的数量来确定是否无法区分两个名称。此外,提供了示例输入和输出,帮助读者理解解决方案的具体应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Country List

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable to be a volunteer of such an international pageant. His job is to guide the foreign visitors. Although he has a strong desire to be an excellent volunteer, the lack of English makes him annoyed for a long time.
Some countries’ names look so similar that he can’t distinguish them. Such as: Albania and Algeria. If two countries’ names have the same length and there are more than 2 same letters in the same position of each word, CC cannot distinguish them. For example: Albania and AlgerIa have the same length 7, and their first, second, sixth and seventh letters are same. So CC can’t distinguish them.
Now he has received a name list of countries, please tell him how many words he cannot distinguish. Note that comparisons between letters are case-insensitive.
 

 

Input
There are multiple test cases.
Each case begins with an integer n (0 < n < 100) indicating the number of countries in the list.
The next n lines each contain a country’s name consisted by ‘a’ ~ ‘z’ or ‘A’ ~ ‘Z’.
Length of each word will not exceed 20.
You can assume that no name will show up twice in the list.
 

 

Output
For each case, output the number of hard names in CC’s list.
 

 

Sample Input
3 Denmark GERMANY China 4 Aaaa aBaa cBaa cBad
 

 

Sample Output
2 4
 
 
#include <cstdio>
#include <cstring>
char str[101][21];
int vis[101];
int main(){
    int t;
    while(scanf("%d", &t)!= EOF){
        int sum = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < t; i++){
                scanf("%s", str[i]);
                for(int k = 0; k < strlen(str[i]); k++)
                    if(str[i][k] >= 'A' && str[i][k] <= 'Z')
                        str[i][k] = str[i][k] + 32;
            }
        for(int i = 0; i < t; i++){
            int G = 0;
            for(int j = 0; j < t; j++){
                int cnt = 0;
                int a = strlen(str[i]);
                int b = strlen(str[j]);
                if(a == b){
                        for(int k = 0, f = 0; f < b; f++, k++)
                            if(str[i][k] == str[j][f])
                                cnt++;
                        if(cnt > 2 && cnt != a)
                            G++;
                }
                if(G)
                    break;
            }
            if(G)    
                vis[i] = 1;
                
        }
        for(int i = 0; i < t; i++){
            if(vis[i])
                sum++;
        }
            printf("%d\n", sum); 
    } 
    return 0;
}

 

 

The Magic Tower

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Like most of the RPG (role play game), “The Magic Tower” is a game about how a warrior saves the princess.
After killing lots of monsters, the warrior has climbed up the top of the magic tower. There is a boss in front of him. The warrior must kill the boss to save the princess.
Now, the warrior wants you to tell him if he can save the princess.
 

Input
There are several test cases.
For each case, the first line is a character, “W” or “B”, indicating that who begins to attack first, ”W” for warrior and ”B” for boss. They attack each other in turn.
The second line contains three integers, W_HP, W_ATK and W_DEF. (1<=W_HP<=10000, 0<=W_ATK, W_DEF<=65535), indicating warrior’s life point, attack value and defense value.
The third line contains three integers, B_HP, B_ATK and B_DEF. (1<=B_HP<=10000, 0<=B_ATK, B_DEF<=65535), indicating boss’s life point, attack value and defense value.

Note: warrior can make a damage of (W_ATK-B_DEF) to boss if (W_ATK-B_DEF) bigger than zero, otherwise no damage. Also, boss can make a damage of (B_ATK-W_DEF) to warrior if (B_ATK-W_DEF) bigger than zero, otherwise no damage.
 

Output
For each case, if boss’s HP first turns to be smaller or equal than zero, please print ”Warrior wins”. Otherwise, please print “Warrior loses”. If warrior cannot kill the boss forever, please also print ”Warrior loses”.
 

Sample Input
W 100 1000 900 100 1000 900 B 100 1000 900 100 1000 900
 

Sample Output
Warrior wins Warrior loses
 
//相死, 攻击和护盾是定值, 用数组!!!!!
 
#include <cstdio>
int main(){
    char ch[10];
    while(scanf("%s", ch)){   /*************************/
        int a, b, c, d, e, f;
        scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
        if(b-f <= 0 && e-c <= 0){
                printf("Warrior loses\n");
                continue;
        }
        if(ch == 'W'){
            while(1){
                d -= b-f;
                if(d <= 0)
                    break;
                a -= e-c;
                if(a <= 0)
                    break; 
            }
        }
        else{
                while(1){
                a -= e-c;
                if(a <= 0)
                    break;
                d -= b-f;
                if(d <= 0)
                    break;
            }
        }
        if(d <= 0)
            printf("Warrior wins\n");
        if(a <= 0)
            printf("Warrior loses\n");
    }
    return 0;
}

 

 
 

转载于:https://www.cnblogs.com/soTired/p/5078288.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值