黑龙江农垦科技职业学院喜迎寒假多校联赛2——题解

J题
比赛开始了清楚姐姐喊了一句:签到了签到了 选手们纷纷开始签到,现在给出n个数字代表选手们签到所用秒数 请给出第几个选手最先签到。同秒数先输入的算快。
(不会吧 不会吧 不会有人用牛客不知道清楚姐姐吧)
输入描述:
第一行输入一个整数n
1<=n<=10000
第二行输入n个整数s
0<=s<=1000
输出描述:
一个数

示例1
输入
5
5 3 2 4 1

输出
5

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>


using namespace std;

int main()
{
     int n,num[10010];
    cin>>n;
    for(int i=1;i<=n;i++)  cin>>num[i];
    int m=min_element(num+1,num+n+1)-num;//求数组最小值的地址
    cout<< m << endl;

    return 0;
}

G题
又是欢快的一天,牛客多校算法训练营4又在日常%Alan。qcjj想知道到底Alan被%了多少次,所以整理了一下聊天记录。
如果一句话中存在Alan,那么那句话中的%都算%了Alan。由于可能话中有空格,所以去掉空格后形成的Alan也算Alan。
输入描述:
第一行输入整数n表示聊天记录行数
1<=n<=1000
以下n行每行一个字符串s代表聊天记录
1<=s.length<=1000
输出描述:
输出%Alan次数

示例1
输入
5
%alan%%
%Alan%%%
cdqwsq%% A l a n%%
%AC lan%%
%Alan%%%

输出
12

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>


using namespace std;

int main()
{
    int n,sum=0;

    string s,str;
    scanf("%d",&n);
    getchar();//吸收换行符
    for(int j=0;j<n;j++)
    {
        int flog=1,num=0,l=0;
        getline(cin,s);//输入s字符串
        str.clear();//清空str字符串
        for(int i=0;i<s.size();++i)
        {
            if(s[i]=='%') num++;//统计'%'数量
            if(s[i]!=' '&&l>0&&l<4)//判断赋值条件
            {
                str.push_back(s[i]);
                l++;
            }
            if(s[i]=='A'&&flog)//从'A'开始将字符赋给str字符串
            {
                str.push_back(s[i]);
                flog=0;
                l++;
            }
        }
        if(str=="Alan"&&str.size()>=0)//判断'%'数量相加条件
        {
            sum+=num;
        }
    }
    printf("%d\n",sum);

    return 0;
}

C题
这一天gg拿到了一份,超多的考试数据a 。
老师要求他按照询问数据告诉老师,第几个到第几个同学的分数和是多少 ?
gg最近入职字节跳动了,没有时间处理这种极其简单的问题,所以请你顺手秒一下。

输入描述:
第一行n m ( n个同学 m次询问)
1<=n<=106
1<=m<=104
第二行输入n个整数表示成绩
a1 a2 …an (0<=ai<=100) 1<=i<=n
以下m行为两个整数bi bj 表示第几个到第几个同学(从1开始)
1<=bi<=bj<=n
输出描述:
m行查询结果

示例1
输入
10 3
11 22 33 44 55 66 77 88 99 10
1 4
2 10
5 7

输出
110
494
198

说明
注意第几个是按照输入顺序 不要排序 不要排序 不要排序

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

const int N=1e6+10;
int a[N],arr[N];
int  n,m;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        arr[i]=arr[i-1]+a[i];//储存前i个数之和;
    }
    while(m--)
    {
        int i,j;
        cin>>i>>j;
        cout<< arr[j]-arr[i-1] << endl;//通过前J个数之和-前i-1个数之和得i到j个数之和;
    }
    return 0;
}

B题
群友们在玩一个游戏,共n个人在玩 每个人要在0-(n-1)中选一个数,注意每个数只能选择一次,
然后按照先后选择顺序拼成一个数,计算组成的数字是否可以整除k,
群友们想知道,如果选择方案不重复,最多有多少种情况可以整除k?
如果不可能整除k请输出-1;
输入描述:
第一行输入两个正整数 n,k
1<=n<=10,1<=k<=107

输出描述:
输出结果
示例1
输入
2 1

输出
2

说明
01 10 两种组合除以1都可以除开

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
int main()
{
    ll n,k,sum=0;
    int num[10];
    cin>>n>>k;
    for(int i=0;i<n;i++)  num[i]=i;
    do
    {
        ll f=0;
        for(int i=0;i<n;i++) f=f*10+num[i];//将数组变为数
        if(f%k==0) cnt++;//判断是否可以整除k
    }while(next_permutation(num,num+n));//关键:全排列函数——next_permutation(num,num+n)
    //输出判断
    if(cnt!=0) cout<< cnt << endl;
    else cout << "-1" << endl;
    
    return 0;
}

H题
这一天cg写了一个卡迪亚酒店客户端,客户端的数据是一张由用户名s,密码m,性别x,电话h组成的表,他想以用户的用户名为基准进行一下排序,短的在前,同样长度按照字典序小的在前,同用户名先输入的在前面。但是曹哥太忙了所以找你帮忙写一下数据处理。
输入描述:
n分数据
1<=n<=100
以下n行 为 s m x h
1<= s.length <=20
1<= m.length <=20
1<= x.length <=20
1<= h.length <=20
输出描述:
根据用户名排序规则排序后输出
链接:https://ac.nowcoder.com/acm/contest/11471/H
来源:牛客网

输入
5
td1336065617 1336065617 n 13766949653
1336065617 1336065617 nc 137
ad1336065617 1336065617 na 111
03360651778 1 9 8
1 1 1 1

输出
1 1 1 1
1336065617 1336065617 nc 137
03360651778 1 9 8
ad1336065617 1336065617 na 111
td1336065617 1336065617 n 13766949653

备注:
记得快读

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

struct people
{
    string s,m,x,h;
    int index,leng;
}name[100];

//排序条件
bool cmp(people a,people b)
{
    if(a.leng != b.leng) return  a.leng<b.leng;//判断长度从短到长
    if(a.s != b.s) return a.s<b.s;//判断相同长度字典序从小到大
    return a.index<b.index;//先输入的在前面
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>name[i].s>>name[i].m>>name[i].x>>name[i].h;
        name[i].index=i;//保存地址
        name[i].leng=name[i].s.size();//保存名字长度

    }
    sort(name,name+n,cmp);//排序

    for(int i=0;i<n;++i)
    {
        cout<< name[i].s<< ' '<< name[i].m<< ' ' << name[i].x<< ' ' << name[i].h<< endl;
    }
    
    return 0;
}

I题
这一天cg写了一个卡迪亚酒店客户端,客户端的数据是一张由用户名s,密码m,性别x,电话h组成的表,他想以用户的用户名为基准进行一下排序,短的在前,同样长度按照字典序小的在前,同用户名先输入的在前面。但是曹哥太忙了所以找你帮忙写一下数据处理。
输入描述:
n分数据
1<=n<=106
以下n行 为 s m x h
1<= s.length <=20
1<= m.length <=20
1<= x.length <=20
1<= h.length <=20
输出描述:
根据用户名排序规则排序后输出

示例1
输入
5
td1336065617 1336065617 n 13766949653
1336065617 1336065617 nc 137
ad1336065617 1336065617 na 111
03360651778 1 9 8
1 1 1 1

输出
1 1 1 1
1336065617 1336065617 nc 137
03360651778 1 9 8
ad1336065617 1336065617 na 111
td1336065617 1336065617 n 13766949653

和H题差距不大,就是数组要开大点

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
 
using namespace std;
 
const int N=1e6+10;//数组要开大点
 
struct people
{
    string s,m,x,h;
    int index,leng;
}name[N];
 
//排序条件
bool cmp(people a,people b)
{
    if(a.leng != b.leng) return  a.leng<b.leng;//判断长度从短到长
    if(a.s != b.s) return a.s<b.s;//判断相同长度字典序从小到大
    return a.index<b.index;//先输入的在前面
}
 
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>name[i].s>>name[i].m>>name[i].x>>name[i].h;
        name[i].index=i;//保存地址
        name[i].leng=name[i].s.size();//保存名字长度
 
    }
    sort(name,name+n,cmp);//排序
 
    for(int i=0;i<n;++i)
    {
        cout<< name[i].s<< ' '<< name[i].m<< ' ' << name[i].x<< ' ' << name[i].h<< endl;
    }
 
    return 0;
}```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值