阿里巴巴2021秋招笔试题20211119
生活随笔
收集整理的這篇文章主要介紹了
阿里巴巴2021秋招笔试题20211119
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源代碼:https://gitee.com/shentuzhigang/algorithm/tree/master/exam-alibaba/exam-alibaba-20211119
第一題
題目大意:
有長度為n的數組a
有k次機會在連續長度不超過m的區間每個元素+1使得數組全部元素變成偶數
第二題
(未驗證正確性)
題目大意:
有 單詞組 strs
人數n,長度b
每個人按單詞組依次報【0,i】
例:
king
king hello
king hello wrold
king hello
king
king hello
king hello wrold
king hello
求單詞word第X次出現在第幾行
import java.util.Scanner;/*** @author ShenTuZhiGang* @version 1.0.0* @email 1600337300@qq.com* @date 2021-11-19 20:36*/ public class Exam2021111902 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();int b = scanner.nextInt();scanner.nextLine();String[] s = scanner.nextLine().split(" ");String word = s[0];int c = Integer.parseInt(s[1]);String[] strs = scanner.nextLine().split(" ");if(b==1){System.out.println(b);System.exit(0);}int t = 0;for (int i = 0; i < 2*b-2; i++) {for (int j = 0; j <= i; j++) {if(word.equals(strs[j%n])){t++;}}}int k = c/t;int t0 = c%t;if(t0!=0){for (int i = 0; i < 2*b-2; i++) {for (int j = 0; j <= i; j++) {if(word.equals(strs[j%n])){t0--;if(t0==0){System.out.println(k*(2*b-2)+i);}}}}}else {System.out.println(k*(2*b-2));}}}總結
以上是生活随笔為你收集整理的阿里巴巴2021秋招笔试题20211119的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 36 有效的数独
- 下一篇: Web安全——服务器端请求伪造(SSRF