华为机试2016 (第一题和第二题和第三题)

#include <iostream>
#include <bits/stdc++.h>
#define maxn 30000+10
using namespace std;
int n,m;
int A[maxn];

int main()
{
    char c;
    int a,b;
    while(cin>>n>>m)
    {
        for(int i = 1;i<=n;i++)
        {
            cin>>A[i];
        }
        for(int i = 0;i<m;i++)
        {
            cin>>c>>a>>b;
            if(c=='Q')
            {
                int a1 = min(a,b);
                int b1 = max(a,b);
                int temp = A[a1];
                int t = a1;
                for(int j = a1;j<=b1;j++)
                {
                    temp = max(temp,A[j]);

                }
                cout<<temp<<endl;
            }
            else
            {
                A[a] = b;
            }
        }
    }
    return 0;
}
/**
17 9
57 6 6 49 44 38 12 41 52 43 57 21 2 20 1 30 39
Q 3 9
U 9 34
Q 14 7
U 8 78
U 5 79
Q 1 7
Q 11 4
Q 12 6
Q 13 4

**/

 

 

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

struct Record{
    string name;
    int num;
    int c;
    Record(string s,int t,int c1):name(s),num(t),c(c1){}
    Record(){}
    const bool operator < (const Record & a)const
    {
       if(name == a.name){
            return num<a.num;
       }
       else
            return name < a.name;
    }
};

Record records[100000];
set<Record>IdCount;


bool cmp(const Record & a,const Record & b){
    return a.c>b.c;
}

string getName(string s)
{
    int pos = 0;
    if((pos = s.rfind('\\'))!=string:: npos)
    {
        string t = s.substr(pos+1,s.size()-pos-1);
        return t;
    }
    return s;
}



int main()
{
    string s,t;
    string root;
    int num;
    int kase = 0;
   // memset(C,0,sizeof(C));
    IdCount.clear();
    while(cin>>root>>num)
    {
        t = getName(root);
        if(IdCount.count(Record(t,num,0)) == 0)
        {
            IdCount.insert(Record(t,num,0));
            if(t.size()>16)
            {
                t = t.substr(t.size()-16,16);
                //cout<<t<<endl;
            }
            records[kase++] = Record(t,num,1);
            //C[kase++]++;
        }
        else
        {
            if(t.size()>16)
            {
                t = t.substr(t.size()-16,16);
                //cout<<t<<endl;
            }
            for(int i = 0;i<kase;i++)
            {
                if(records[i].name == t && records[i].num == num)
                {
                    records[i].c++;
                    break;
                }
            }
        }

    }
    sort(records,records+kase,cmp);
    kase = min(kase,8);
    for(int i = 0;i<kase;i++)
    {
        cout<<records[i].name<<" "<<records[i].num<<" "<<records[i].c<<endl;
    }
    return 0;
}
/**
e:\1\aa3.txt 3
e:\3\aa1.txt 2
e:\2\aa2.txt 3
e:\3\aa1.txt 1
e:\1\aa1.txt 3
e:\3\aa1.txt 2
e:\1\aa3.txt 3
e:\2\aa3.txt 2
e:\1\aa1.txt 2
e:\3\aa3.txt 2
e:\1\aa2.txt 2
e:\1\aa3.txt 1
e:\1\aa3.txt 1
e:\2\aa3.txt 2
e:\1\aa2.txt 1 e:\3\aa1.txt 2 e:\1\aa1.txt 3 e:\2\aa1.txt 1 e:\3\aa3.txt 2 e:\1\aa1.txt 1 e:\2\aa2.txt 2 e:\3\aa3.txt 2 e:\1\aa2.txt 1 e:\1\aa3.txt 2 e:\1\aa3.txt 3 e:\1\aa2.txt 3 e:\3\aa1.txt 3 e:\2\aa2.txt 2 e:\1\aa1.txt 1 e:\2\aa3.txt 1 e:\3\aa1.txt 1 e:\2\aa1.txt 3 e:\3\aa3.txt 2 e:\1\aa3.txt 3 e:\2\aa3.txt 3 e:\1\aa2.txt 3 e:\2\aa2.txt 1 e:\1\aa3.txt 1 e:\1\aa3.txt 1 e:\3\aa3.txt 3 e:\3\aa3.txt 2 e:\1\aa2.txt 3 e:\1\aa2.txt 3 e:\1\aa2.txt 3 e:\1\aa1.txt 1 e:\2\aa3.txt 1 e:\3\aa3.txt 1 e:\2\aa3.txt 2 e:\3\aa1.txt 3 e:\2\aa2.txt 2 e:\2\aa2.txt 2 e:\2\aa3.txt 1 e:\1\aa3.txt 3 e:\3\aa1.txt 2 e:\3\aa2.txt 2 e:\1\aa2.txt 1 e:\2\aa2.txt 1 e:\2\aa1.txt 2 e:\2\aa2.txt 1 e:\1\aa2.txt 1 e:\2\aa3.txt 1 e:\2\aa2.txt 1 e:\2\aa1.txt 2 e:\3\aa2.txt 3 e:\3\aa1.txt 3 e:\2\aa2.txt 3 e:\2\aa3.txt 1 e:\3\aa3.txt 2 e:\2\aa3.txt 1 e:\1\aa1.txt 2 e:\3\aa3.txt 1 e:\3\aa1.txt 1 e:\2\aa2.txt 3 e:\3\aa3.txt 2 e:\2\aa1.txt 3 e:\1\aa3.txt 3 e:\3\aa2.txt 1 e:\2\aa1.txt 3 e:\1\aa3.txt 3 e:\2\aa2.txt 2 e:\1\aa1.txt 2 e:\3\aa1.txt 1 e:\1\aa3.txt 1 e:\3\aa1.txt 2 e:\1\aa1.txt 2 e:\1\aa1.txt 3 e:\3\aa1.txt 1 e:\3\aa1.txt 1 e:\2\aa3.txt 3 e:\2\aa2.txt 1 e:\2\aa1.txt 2 e:\2\aa2.txt 1 e:\3\aa2.txt 3 e:\1\aa2.txt 1 e:\3\aa2.txt 2 e:\2\aa1.txt 1 e:\2\aa3.txt 3 e:\1\aa1.txt 2 e:\1\aa1.txt 1 e:\1\aa1.txt 2
e:\1\aa3.txt 3
e:\1\aa3.txt 3
**/

 

前两题略水,第三题比较有意思~

等下再写。

#include <iostream>
#include <bits/stdc++.h>
#define maxn 20
using namespace std;

vector<int>P1;
vector<int>P2;
vector<string>Ps1;
vector<string>Ps2;
int num1,num2;

bool isContain(char c,string s)
{
    for(int i = 0; i<s.size(); i++)
    {
        if(s[i]==c)
            return 1;
    }
    return 0;
}

int changeIt(string s)
{
    if(s.size() == 1)
    {
        char c = s[0];
        if(c>='3'&&c<='9') return c-'0';
        else if(c>='J'&&c<='K') return c-'J'+11;
        else if(c == 'A') return 14;
        else return 15;
    }
    else if(s == "joker")
        return 16;
    else if(s == "10")
        return 10;
    else
        return 17;
}

void init()
{
    P1.clear();
    P2.clear();
    Ps1.clear();
    Ps2.clear();
}

void split(string s,string & s1,string & s2)
{
    int pos = s.find('-');
    s1 = s.substr(0,pos);
    s2 = s.substr(pos+1,s.size()-pos-1);
    //cout<<s1<<" "<<s2<<endl;
}


bool cmp(const int & a,const int & b)
{
    return a<b;
}


/**
3-9   3-9
A     1
2     2
joker 10
JOKER 11
**/

int main()
{
    string s;
    char c;
    int flag  = 0;
    int win = 0;

    while(getline(cin,s))
    {
        init();
        win = 0;
        string s1,s2;
        split(s,s1,s2);
        stringstream ss(s1);
        while(ss>>s)
        {
            P1.push_back(changeIt(s));
            Ps1.push_back(s);
        }
        stringstream ss1(s2);
        while(ss1>>s)
        {
            P2.push_back(changeIt(s));
            Ps2.push_back(s);
        }
        if((P1[0] == 16 && P1[1] == 17) || (P1[0] == 17 && P1[1] == 16))
        {
            win = 1;
        }
        else if((P2[0] == 16 && P2[1] == 17) || (P2[0] == 17 && P2[1] == 16))
        {
            win = 2;
        }
        else if(P1.size() == P2.size() && P1.size()<6 && P1.size()>0)
        {
            if(P1[0]>P2[0])
                win = 1;
            else
                win = 2;
        }
        else if(P1.size() == 4)
        {
            win = 1;
        }
        else if(P2.size()==4)
        {
            win = 2;
        }

        if(win == 1)
        {
            for(int i = 0; i<Ps1.size(); i++)
            {
                cout<<Ps1[i]<<" ";
            }
            cout<<endl;
        }
        else if(win == 2)
        {
            for(int i = 0; i<Ps2.size(); i++)
            {
                cout<<Ps2[i]<<" ";
            }
            cout<<endl;
        }
        else
            cout<<"ERROR"<<endl;
    }

    return 0;
}
/**
4 4 4 4-joker JOKER
2 2 2 2-K K
A-10
**/

写完啦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值