拼多多 100,100,5,30

第一题  奇偶数优先级排序  AC 100
import os 
import sys 

def Fn(data:list, N):
    data.sort(reverse=True) 
    a = [str(x) for x in data if x%2==0]
    b = [str(x) for x in data if x%2!=0]
    data = a+b print(",".join(data[0:N])) 

def main():
    line = sys.stdin.readline().strip()
    line = line.split(';')
    data = list(map(int, line[0].split(',')))
    N = int(line[1])
    Fn(data, N) if __name__=='__main__':
    main()


第二题  扑克牌 AC 100
#pragma once
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

void FnCore(string S1, const string &S2,
	int N, 
	string newString, 
	string round,
	vector<string>&res)
{
	if (newString == S2 && round.size() == N)
	{
		res.push_back(round);
		return;
	}
	if (S1.size() < 1 || round.size() > N)
		return;

	FnCore(S1.substr(1), S2, N, newString, round + 'd', res);
	FnCore(S1.substr(1), S2, N, S1[0]+newString, round + 'l', res);
	FnCore(S1.substr(1), S2, N, newString+ S1[0], round + 'r', res);

}

void Fn(string S1, string S2)
{
	vector<string>res;
	FnCore(S1, S2, S1.size(), "", "", res);

	if (res.size() > 0)
		sort(res.begin(), res.end());

	for (int i = 0;i < res.size();++i)
	{
		for (int j = 0;j<res[i].size();++j)
		{
			printf("%c ", res[i][j]);

		}
		cout << endl;
	}	
}

int main()
{

	int S;
	cin >> S;
	string S1, S2;
	for (int i = 0;i < S;++i)
	{
		cin >> S1;
		cin >> S2;
		cout << "{" << endl;
		Fn(S1, S2);
		cout << "}" << endl;
	}

	return 0;

}
第三题 掷骰子 AC 5
import os
import sys

def FnCore(X, ret, count, index, CurMax):
    if index==len(X):
        count[CurMax-1]+=1
        return
    for i in range(1, X[index]+1):
        ret.append(i)
        if i>CurMax:
            CurMax=i
        FnCore(X, ret, count, index+1,CurMax)
        del ret[-1]

def Fn(X):
    maxVal = max(X)
    count = [0]*maxVal
    ret = []
    CurMax= 0
    FnCore(X, ret, count, 0,CurMax)
    Total = sum(count)
    P = 0
    for i in range(len(count)):
        P+=(i+1)*count[i]/Total
    P = round(float(P), 2)
    print(P)

def main():
    n = int(input())
    X = list(map(int, sys.stdin.readline().strip().split(' ')))
    Fn(X)



if __name__=='__main__':
    main()
第四题 寻找矩阵中第K大的数  AC 30
#pragma once
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int Fn(int N, int M, int K)
{
	priority_queue<int, vector<int>, less<int>>data;
	for(int i = N;i>=1;--i)
		for (int j = M;j >= 1;--j)
		{
			data.push(i*j);
		}

	for (int r = 0;r < K-1;++r)
	{
		data.pop();
	}
	int ret = data.top();
	return ret;

}

int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	int ret = Fn(N, M, K);
	cout << ret;

	return 0;

} 

#拼多多##笔试题目##题解#
全部评论
第四题: #include<iostream> #include<vector> #include<algorithm> #include<ctime> using namespace std; int main() {     clock_t startTime, endTime;     startTime = clock();     int N, M, k;     cin >> N >> M >> k;     if (N <= 0 || M <= 0)     {         return 0;     }     vector<int> arr;     int ss = (int)sqrt(k);     //cout << ss;     int nIndex = N;     int mIndex = M;     if (k > N*M || N <= 0 || M <= 0)     {         return 0;     }     if (N == M)     {         int judge = k - 1;         while (judge)         {             if (nIndex == mIndex && nIndex >= 1 && mIndex >= 1)             {                 nIndex--;                 mIndex = M;                 --judge;             }             else if (nIndex < mIndex && nIndex >= 1 && mIndex >= 1)             {                 if (judge>1)                 {                     judge = judge - 2;                     mIndex--;                 }                 else if (judge == 1)                 {                     --judge;                 }             }         }         cout << nIndex*mIndex <<endl;     }     if (N < M)     {         int judge = k - 1;         while (judge)         {             if (nIndex < mIndex && mIndex > N && mIndex >= 1 && nIndex >= 1)             {                 --judge;                 --mIndex;             }             else if (nIndex < mIndex && mIndex <= N && mIndex >= 1 && nIndex >= 1)             {                 if (judge > 1)                 {                     judge = judge - 2;                     --mIndex;                 }                 else if (judge == 1)                 {                     --judge;                 }             }             else if (nIndex == mIndex)             {                 --nIndex;                 mIndex = M;                 --judge;             }         }         cout << nIndex*mIndex <<endl;     }     if (N>M)     {         int judge = k - 1;         while (judge)         {             if (nIndex == mIndex && mIndex >= 1 && nIndex >= 1)             {                 --mIndex;                 nIndex = N;                 --judge;             }             else if (mIndex < nIndex && nIndex > M && mIndex >= 1 && nIndex >= 1)             {                 --judge;                 --nIndex;             }             else if (mIndex < nIndex && nIndex <= M && mIndex >= 1 && nIndex >= 1)             {                 if (judge > 1)                 {                     judge = judge - 2;                     --nIndex;                 }                 else if (judge == 1)                 {                     --judge;                 }             }         }         cout << nIndex*mIndex<<endl;     }     endTime = clock();     cout << "运行时间:" << endTime - startTime << "ms"<< endl;     system("pause");     return 0; }
点赞 回复 分享
发布于 2019-09-01 18:56
第四题leetcode 668
点赞 回复 分享
发布于 2019-09-01 19:05
大佬可以帮忙看下第二题我这样做有什么问题吗? import java.util.ArrayList; import java.util.Scanner; public class Poke { public static void main(String[] args){ Scanner in = new Scanner(System.in); int s=in.nextInt(); String[][]a=new String[s][2]; for(int i=0;i<s;i++){ a[i][0]=in.next(); a[i][0].trim(); a[i][1]=in.next(); } StringBuilder result=new StringBuilder(); for(int i=0;i<s;i++){ StringBuilder ans=new StringBuilder(); StringBuilder ans2=new StringBuilder(); ArrayList<Integer> mei=new ArrayList<>(); ArrayList<Integer> tmp=new ArrayList<>(); ArrayList<Integer> ming=new ArrayList<>(); String a0=a[i][0]; String a1=a[i][1]; for(int x=0;x<a0.length();x++){ mei.add(a0.charAt(x)-'0'); } for(int x=0;x<a1.length();x++){ ming.add(a1.charAt(x)-'0'); } int count=0; for(int j=0;j<mei.size();j++){ if(!ming.contains(mei.get(j))){ ans.append("d "); ans2.append("d "); }else{ if(count==0){ ans.append("l "); ans2.append("r "); tmp.add(mei.get(j)); count++; }else{ if(ming.indexOf(mei.get(j))<ming.indexOf(mei.get(j-1))){ ans.append("l "); ans2.append("l "); tmp.add(0,mei.get(j)); }else{ ans.append("r "); ans2.append("r "); tmp.add(tmp.size()-1,mei.get(j)); } } } } if(tmp.size()==0){ result.append("{"+"\n"); result.append("}"+"\n"); break; } for(int x=0;x<tmp.size();x++){ if(tmp.get(x)!=ming.get(x)){ result.append("{"+"\n"+"}"); break; } } result.append("{"+"\n"); result.append(ans); result.append("\n"); result.append(ans2+"\n"); result.append("}"+"\n"); } System.out.println(result); } }
点赞 回复 分享
发布于 2019-09-01 19:16
第二题小梅那个是不是抽出的牌中可能有重复的?
点赞 回复 分享
发布于 2019-09-01 19:16
同楼主差不多分数 希望能有面试
点赞 回复 分享
发布于 2019-09-02 07:43

相关推荐

10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
2 14 评论
分享
牛客网
牛客企业服务