http://www.cnblogs.com/live-no-regrets/

考场细节题初体验

以下代码:

#include<bits/stdc++.h>
#define N 500000
using namespace std;
string tree[N];
int tl;
bool fault;
void robot()
{
    cout<<"robot: ";
}
string cut_user(string &s1)
{
    int pla=s1.find(":",0);
    if (pla==string::npos){fault=true;return "";}
    
    string sname=s1.substr(0,pla);
    s1.erase(0,pla+1);
    return sname;
}
bool find(string s1,string ord)
{
    int len=ord.length(),len1=s1.length(),i=0,j=0;
    for (i=0;i<=len1-len&&s1[i]==' ';i++);
    if (i+len>len1)return false;
    
    for (j=0;j<len;j++)
        if (ord[j]!=s1[i+j])break;
    if (j==len)return true;
    return false;
}
bool find(string s1,string ord,int &sum)
{
    int len=ord.length(),len1=s1.length(),i=0,j=0;
    for (i=0;i<=len1-len&&s1[i]==' ';i++);
    if (i+len>len1)return false;
    for (j=0;j<len;j++)
        if (ord[j]!=s1[i+j])break;
    
    if (j<len)return false;
    
    sum=0;
    for (i=i+j;i<len1&&s1[i]==' ';i++);
    for (;i<len1&&s1[i]>='0'&&s1[i]<='9';i++)sum=sum*10+s1[i]-'0';
    return true;
}
void tree_find(string sname,bool &oo)
{
    for (int i=1;i<=tl;i++)
        if (tree[i]==sname){oo=true;return;}
    oo=false;
}
void clear_tree()
{
    if (tl==0)return;
    
    robot();
    cout<<"下树提醒: ";
    for (int i=1;i<=tl;i++)cout<<"@"<<tree[i];
    cout<<"\n";
    tl=0;
}
int main()
{
    string s1,sname,pre="";
    int zhumu,bossnum,bosshp;
    zhumu=1;bossnum=1;bosshp=6000000;
    tl=0;pre="";
    while (getline(cin,s1,'\n')){//great
        fault=false;
        sname=cut_user(s1);
        if (fault)continue;
        
        bool tree_=false;
        tree_find(sname,tree_);
        int arg;
        if (find(s1,"APPLY")&&!tree_){
            if (pre!=""){
                robot();cout<<pre<<"正在出刀,请勿进场!\n";
            } else {
                robot();cout<<sname<<"成功申请出刀\n";
                pre=sname;
            }
        } else if (find(s1,"Report",arg)&&!tree_){
            if (sname==pre)pre="";
            if (arg>=bosshp){
                bosshp=6000000;
                bossnum++;
                if (bossnum>5){bossnum=1,zhumu++;}
                robot();cout<<sname<<"出刀成功,成功斩杀BOSS.\n";
                pre="";
                clear_tree();
            } else {
                bosshp-=arg;
                robot();cout<<sname<<"出刀成功,伤害为"<<arg<<",当前BOSS血量为"<<bosshp<<".\n";
            }
        } else if (find(s1,"QUERY")){
            robot();cout<<"状态: { 当前周目: "<<zhumu<<" BOSS编号: "<<bossnum<<" BOSSHp: "<<bosshp<<"; }\n";
            ///robot: 状态: { 当前周目: 3 BOSS编号: 3 BOSSHp: 6666666; }
        } else if (find(s1,"TREE")&&!tree_){
            tree[++tl]=sname;
            if (sname==pre)pre="";
        }
        
        //getchar();///great
    }
    return 0;
}

 

posted @ 2021-01-02 22:14  voyage~st~Imagine  阅读(57)  评论(0编辑  收藏  举报