B - Baby Bites

Arild just turned 1 year old, and is currently learning how to count. His favorite thing to count is how many mouthfuls he has in a meal: every time he gets a bite, he will count it by saying the number out loud.
Unfortunately, talking while having a mouthful sometimes causes Arild to mumble incomprehensibly, making it hard to know how far he has counted. Sometimes you even suspect he loses his count! You decide to write a program to determine whether Arild’s counting makes sense or not.

Input
The first line of input contains an integer n (1≤n≤1000), the number of bites Arild receives. Then second line contains n space-separated words spoken by Arild, the i’th of which is either a non-negative integer ai (0≤ai≤10000) or the string “mumble”.

Output
If Arild’s counting might make sense, print the string “makes sense”. Otherwise, print the string “something is fishy”.

Sample Input 1 Sample Output 1
5
1 2 3 mumble 5
makes sense
Sample Input 2 Sample Output 2
8
1 2 3 mumble mumble 7 mumble 8
something is fishy
Sample Input 3 Sample Output 3
3
mumble mumble mumble
makes sense

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;

int a[maxn];
string s[maxn];//字符串数组
int main()
{
    int flag = 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];//输入字符串。
    }
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == "mumble")
            continue;
        if (isdigit(s[i][0]))//判断(注:isdigit仅能将字符转化为数字。)
        {
            int num = stoi(s[i]);//将字符串转化为数字。//注:此函数在c++11中无法通过编译。stoi是将字符转化为数字。
            if (num != i)
                flag = 0;//不等于i无法成立。
        }
    }
    if (flag)
        cout << "makes sense" << endl;
    else
        cout << "something is fishy" << endl;
    return 0;
}
好的,我看到您的代码中有一些拼写错误和缩进问题。以下是修改后的代码: ``` class Character: def __init__(self, name, health, power): self.name = name self.health = health self.power = power def attack(self, other): pass def get_status(self): return f"{self.name}: Health={self.health}, Power={self.power}" class Human(Character): def __init__(self, name, health, power, weapon=None): super().__init__(name, health, power) self.weapon = weapon def attack(self, other): if self.weapon is not None: print(f"{self.name} uses {self.weapon} to attack {other.name}!") other.health -= self.power + 5 else: print(f"{self.name} punches {other.name}!") other.health -= self.power def equip_weapon(self, weapon): self.weapon = weapon class Beast(Character): def __init__(self, name, health, power): super().__init__(name, health, power) def attack(self, other): print(f"{self.name} bites {other.name}!") other.health -= self.power human1 = Human("Bob", 100, 10) human2 = Human("Alice", 120, 8, "Sword") beast1 = Beast("Tiger", 80, 15) import random while True: attacker, defender = random.sample([human1, human2, beast1], 2) print(f"{attacker.name} attacks {defender.name}!") attacker.attack(defender) print(defender.get_status()) if defender.health <= 0: print(f"{defender.name} is defeated!") break ``` 修改后的代码中,我主要做了以下几个方面的修改: 1. 将原来的 `def__init__` 修改为了 `def __init__`,修复了拼写错误。 2. 在 `Human` 和 `Beast` 类的 `__init__` 方法中,将 `super().init__` 修改为了 `super().__init__`,修复了拼写错误。 3. 在 `Human` 和 `Beast` 类的 `attack` 方法中,修改了字符串的格式,使其更加易读。 4. 在 `while` 循环中,修改了 `if` 语句中的缩进,使程序能够正确运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值