阿里巴巴2021秋招笔试题20211119
生活随笔
收集整理的這篇文章主要介紹了
阿里巴巴2021秋招笔试题20211119
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
源代碼:https://gitee.com/shentuzhigang/algorithm/tree/master/exam-alibaba/exam-alibaba-20211119
第一題
題目大意:
有長(zhǎng)度為n的數(shù)組a
有k次機(jī)會(huì)在連續(xù)長(zhǎng)度不超過(guò)m的區(qū)間每個(gè)元素+1使得數(shù)組全部元素變成偶數(shù)
第二題
(未驗(yàn)證正確性)
題目大意:
有 單詞組 strs
人數(shù)n,長(zhǎng)度b
每個(gè)人按單詞組依次報(bào)【0,i】
例:
king
king hello
king hello wrold
king hello
king
king hello
king hello wrold
king hello
求單詞word第X次出現(xiàn)在第幾行
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));}}}總結(jié)
以上是生活随笔為你收集整理的阿里巴巴2021秋招笔试题20211119的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: LeetCode 36 有效的数独
- 下一篇: 《移动项目实践》实验报告——Androi