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

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/88778491
#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
**/

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

等下再写。

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/88778491
今日推荐