weixin_53503797 2021-03-27 17:46 采纳率: 0%
浏览 44

魔兽世界第一阶段:备战代码哪里错了,一直WA

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std; 
string headquarternames[2]={"red","blue"};
string soldiernames[5]={"dragon","ninga","iceman","lion","wolf"};
int redorder[5]={2,3,4,1,0};
int blueorder[5]={3,0,1,2,4};
class headquarter{
    public:
    int alllife;
    int colourjudge;
    string headquartername;
    int num;
    int soldiernum[5];
    string soldiername[5];
    int soldierlife[5];
    headquarter(int life, int colour, const int order[], const int lifenum[]) 
    {
        num=0;
        alllife=life;
        colourjudge=colour;
        headquartername=headquarternames[colourjudge];
        for(int i=0; i<5; i++)
        {
            soldiernum[i]=0;
            soldiername[i]=soldiernames[order[i]];
            soldierlife[i]=lifenum[order[i]];
        }
    }
    void soldierproducts(int time, int cnt)
    {
        num++;
        soldiernum[cnt]++;
        cout << setfill('0') << setw(3) << time << " " << headquartername << " " << soldiername[cnt]
        << " " << num << " born with strength " << soldierlife[cnt] << "," << soldiernum[cnt]
        << " " << soldiername[cnt] << " in " << headquartername << " headquarter" << endl;
        alllife -= soldierlife[cnt];
        
    }
    bool stopproduct()
    {
        bool flag=1;
        for(int i=0; i<5; i++)
        {
            if(alllife >= soldierlife[i])
            {
                flag=0;
            }
        }
        return flag;
    }
    ~headquarter(){};
};


int main()
{
    int t=0;
    cin>>t;
    int l=0;
    while(l<t)
    {
        l++;
        int flag1=0,flag2=0;
        int cnt1=0,cnt2=0;
        int m;
        cin>>m;
        int lifenum[5]={0};
        for(int i=0; i<5; i++)
        cin>>lifenum[i];
        cout << "Case:" << l << endl;
        headquarter red=headquarter(m,0,redorder,lifenum);
        headquarter blue=headquarter(m,1,blueorder,lifenum);
        for(int time=0; (!flag1||!flag2); time++)
        {
            if(flag1==0)
            {
                if(red.stopproduct())
                {
                    cout << setfill('0') << setw(3) << time << " red headquarter stops making warriors" << endl;
                    flag1=1;
                }
                else
                {
                    while(1)
                    {
                        if(red.alllife>=red.soldierlife[cnt1])
                        {
                            red.soldierproducts(time,cnt1);
                            if(cnt1==4)
                            cnt1=0;
                            else
                            cnt1++;
                            break;
                        }
                        else
                        {
                            if(cnt1==4)
                            cnt1=0;
                            else
                            cnt1++;
                        }
                    }
                }
            }
            
            if(flag2==0)
            {
                if(blue.stopproduct())
                {
                    cout << setfill('0') << setw(3) << time << " blue headquarter stops making warriors" << endl;
                    flag2=1;
                }
                else
                {
                    while(1)
                    {
                        if(blue.alllife>=blue.soldierlife[cnt2])
                        {
                            blue.soldierproducts(time,cnt2);
                            if(cnt2==4)
                            cnt2=0;
                            else
                            cnt2++;
                            break;
                        }
                        else
                        {
                            if(cnt2==4)
                            cnt2=0;
                            else
                            cnt2++;
                        }
                    }
                }
            }
        } 

    }
    return 0;
}

 

 

题目如下:

描述

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。
红司令部,City 1,City 2,……,City n,蓝司令部

两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。

双方的武士编号都是从1开始计算。红方制造出来的第n个武士,编号就是n。同样,蓝方制造出来的第n个武士,编号也是n。

武士在刚降生的时候有一个生命值。

在每个整点,双方的司令部中各有一个武士降生。

红方司令部按照iceman、lion、wolf、ninja、dragon的顺序循环制造武士。

蓝方司令部按照lion、dragon、ninja、iceman、wolf的顺序循环制造武士。

制造武士需要生命元。

制造一个初始生命值为m的武士,司令部中的生命元就要减少m个。

如果司令部中的生命元不足以制造某个按顺序应该制造的武士,那么司令部就试图制造下一个。如果所有武士都不能制造了,则司令部停止制造武士。

给定一个时间,和双方司令部的初始生命元数目,要求你将从0点0分开始到双方司令部停止制造武士为止的所有事件按顺序输出。
一共有两种事件,其对应的输出样例如下:

1) 武士降生
输出样例: 004 blue lion 5 born with strength 5,2 lion in red headquarter
表示在4点整,编号为5的蓝魔lion武士降生,它降生时生命值为5,降生后蓝魔司令部里共有2个lion武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。

2) 司令部停止制造武士
输出样例: 010 red headquarter stops making warriors
表示在10点整,红方司令部停止制造武士

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,先输出红司令部的,再输出蓝司令部的。

输入

第一行是一个整数,代表测试数据组数。

每组测试数据共两行。

第一行:一个整数M。其含义为, 每个司令部一开始都有M个生命元( 1 <= M <= 10000)。

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于10000。

输出

对每组测试数据,要求输出从0时0分开始,到双方司令部都停止制造武士为止的所有事件。
对每组测试数据,首先输出"Case:n" n是测试数据的编号,从1开始 。
接下来按恰当的顺序和格式输出所有事件。每个事件都以事件发生的时间开头,时间以小时为单位,有三位。

样例输入

1
20
3 4 5 6 7

样例输出

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors
  • 写回答

1条回答 默认 最新

  • 有问必答小助手 2021-03-29 18:55
    关注

    你好,我是问答小助手,本次您提出的有问必答问题,技术专家团超时未为您做出解答

    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

    ​​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    评论

报告相同问题?

悬赏问题

  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?