1、输入任意一个正整数,计算出它的阶乘得数尾部有几个连续的0. 题目编写完毕需要计算出1000的阶乘得数尾部有几个连续的0,需要把这个统计数字打印输出

import java.util.*;
public class Main{static int count0=0;static int count5=0;static int count2=0;public static int countzero(int num,int count){if(num%10!=0){if(num%5==0) {count5=countfive(num,count5);}else if(num%2==0) {count2=counttwo(num,count2);}return count;}else{return countzero(num/10,count+1);}}public static int countfive(int num,int count){if(num%5!=0){return count;}else{return countfive(num/5,count+1);}}public static int counttwo(int num,int count){if(num%2!=0){return count;}else{return counttwo(num/2,count+1);}}public static void main(String[] args){Scanner sc = new Scanner(System.in);int num = sc.nextInt();for(int i=1;i<=num;i++){if(i%10==0){count0=countzero(i,count0);}else if(i%5==0){count5=countfive(i,count5);}else if(i%2==0){count2=counttwo(i,count2);}}count0+=(count2<count5?count2:count5);System.out.println(count0);sc.close();}
}

2、在英文中,有一些标点符号需要成对使用,达到闭合的效果。例如双引号("") 大括号({}) 方括号([])

现在我们需要检测指定文本中的 双引号,大括号, 方括号是否闭合

import java.util.*;
public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);String str = sc.nextLine();Stack<Character> stack=new Stack<Character>();int flag = 0;boolean result = true;for(int i=0;i<str.length();i++){if(str.charAt(i)=='}'){if(stack.pop()!='{') {result = false;break;}}if(str.charAt(i)==']'){if(stack.pop()!='[') {result = false;break;}}if(str.charAt(i)=='{'||str.charAt(i)=='['){stack.add(str.charAt(i));}if(str.charAt(i)=='"') {stack.add(str.charAt(i));flag+=1;}}System.out.println(result&&flag%2==0);sc.close();}
}

3、某风电场每台风机的发电量和距离升压站的距离各不相同,如风机1:发电量30,距离20;风机2:发电量35,距离25;风机3:发电量25,距离18……,要求在输电总距离限定(如小于100)的前提下,选择风机向升压站输电,使得输送的电量最大。

import java.util.*;
public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int max = 0;String str = sc.nextLine();String[] str1 = str.split(" ");int[] dist = new int[str1.length];for(int i=0;i<str1.length;i++){dist[i] = Integer.parseInt(str1[i],10);}str = sc.nextLine();String[] str2 = str.split(" ");int[] elec = new int[str2.length];for(int i=0;i<str1.length;i++){elec[i] = Integer.parseInt(str2[i],10);}int sumdist = sc.nextInt();for(int j=0;j<elec.length;j++){if(max<elec[j]) max=elec[j];for(int k=j+1;k<elec.length;k++){if( dist[j] + dist[k]>sumdist) break;if(max < elec[j] + elec[k]) max = elec[j] + elec[k];}}System.out.println(max);sc.close();}
}

4、给定一个排序好的数组,两个整数 k 和 x,从数组中找到最靠近 x(两数之差最小)的 k 个数。

返回的结果必须要是按升序排好的。如果有两个数与 x 的差值一样,优先选择数值较小的那个数。

import java.util.*;
public class Main{private static void QuickSort(int[] num, int left, int right) {if(left>=right) {return;}int key=num[left];int i=left;int j=right;while(i<j){while(num[j]>=key && i<j){j--;}while(num[i]<=key && i<j){i++;}if(i<j){int temp=num[i];num[i]=num[j];num[j]=temp;}}num[left]=num[i];num[i]=key;QuickSort(num,left,i-1);QuickSort(num,i+1,right);}public static void main(String[] args){Scanner sc = new Scanner(System.in);String str = sc.nextLine();String[] str1 = str.split(",");int[][] arr = new int[str1.length][2];for(int i=0;i<str1.length;i++){arr[i][0] = Integer.parseInt(str1[i],10);}int k = sc.nextInt();int x = sc.nextInt();int[] num = new int[str1.length];for(int i=0;i<str1.length;i++){arr[i][1] = Math.abs(arr[i][0]-x);num[i] = Math.abs(arr[i][0]-x);}QuickSort(num,0,num.length-1);int max = num[k-1];int[] result = new int[k];for(int i=0;i<k;i++){if(arr[i][1]<=max) result[i]=arr[i][0];}for(int i=0;i<k-1;i++) {System.out.print(result[i]+",");}System.out.println(result[k-1]);sc.close();}
}

牛客刷题笔记-远景智能2021秋季招聘软件技术笔试题相关推荐

  1. 远景智能-2021秋季招聘软件技术笔试题(第二批)

    目录 1.进程和线程 2.MD5 3.针对手机软件的系统测试 4.死锁 5.并发和并行的区别 6.算法 7.哈希冲突 8.耦合和内聚 9.协议000000 10.有向图是否有环 10.一些算法对执行时 ...

  2. Python牛客刷题笔记

    一.类型转换 a=input() print(a.lower()) #全小写 print(a.upper()) #全大写 print(a.title()) #首字母大写a=int(input()) p ...

  3. 牛客刷题笔记-数据库选择题(201-300)

    201 在数据库系统中,系统故障造成(C ). 硬盘数据丢失 软盘数据丢失 内存数据丢失 磁带数据丢失 系统故障时,数据库缓冲区(内存)中的内容全被丢失,一些尚未完成的结果可能已送入物理数据库. 20 ...

  4. 牛客刷题笔记--(数组专项练习1-77)

    知识点 设一维数组中有n个数组元素,则读取第i个数组元素的平均时间复杂度为(O(1)) 稀疏矩阵一般采用三元组顺序表方法压缩存储 数组作为函数参数传递的是数组的首地址 在二分查找中,如果剩下的子序列有 ...

  5. 牛客刷题笔记-数据库选择题(101-200)

    101 在学生表 Student 的系别 (Sdept) 属性中查询信息系 (IS) .数学系 (MA) 和计算机系 (CS) 的学生姓名 (Sname) 和性别 (Ssex) ,正确的命名格式应为: ...

  6. 牛客刷题日记(2021-12-8)

    牛客刷题日记(2021-12-8) 题目: 以下哪个接口的定义是正确的?( )interface B { void print() { } ;}interface B { static void pr ...

  7. 【Shell牛客刷题系列】SHELL5 打印空行的行号:一起学习grep命令搭配正则表达式的使用

    该系列是基于牛客Shell题库,针对具体题目进行查漏补缺,学习相应的命令. 刷题链接:牛客题霸-Shell篇. 该系列文章都放到专栏下,专栏链接为:<专栏:Linux>.欢迎关注专栏~ 本 ...

  8. 【牛客刷题专栏】0x27:JZ29 顺时针打印矩阵(C语言编程题)

    前言 个人推荐在牛客网刷题(点击可以跳转),它登陆后会保存刷题记录进度,重新登录时写过的题目代码不会丢失. 个人刷题练习系列专栏:个人CSDN牛客刷题专栏. 题目来自:牛客/题库 / 在线编程 / 剑 ...

  9. 牛客刷题日记(2021-11-24)

    牛客刷题日记(2021-11-24) 题目: 下面程序的输出是:() String x="fmn"; x.toUpperCase(); String y=x.replace('f' ...

最新文章

  1. Google AI 又来放大招,放射科医生会被取代吗?
  2. TAS-LR 论文辅助笔记 图拉普拉斯正则项推导
  3. Oracle SQL语句执行过程
  4. windows下基于IIS配置ssl证书
  5. html to txt研究
  6. python 读取csv文件转成字符串_从CSV读取到 dataframe pandas python时dict对象转换为字符串...
  7. 2017.4.14上午
  8. 在操作系统中进程是如何通信的
  9. c语言新手入门项目代码
  10. 适合初学者的 10 大机器学习项目
  11. 在用mybatis时报错java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedState
  12. 英语表达技巧—委婉地表达消极,否定情感
  13. Justinmind破解
  14. (二)OpenCV-Python学习—对比度增强
  15. 杨浦区服务器维修,上海杨浦区dns服务器地址
  16. 计算机常用英语单词[转]
  17. 问题 G: 曹冲养猪
  18. DLT698.45之数据类型(RSD)
  19. Win32API操作文件
  20. 建国集团与黄江二手车签订战略合作协议

热门文章

  1. CSS权重的问题:选择器权重值的计算
  2. 安卓开发学习笔记(1)使用Bundle在Activity之间交换数据(实例:模拟淘宝的填写并显示收货地址的功能)
  3. android智能语音播放器,android IM模块-语音-播放篇1
  4. IT人才需求稳中有升 3D打印人才需求大
  5. linux中jpg与png相互转化
  6. go : 使用gorm创建数据库记录
  7. JVM理解其实并不难!
  8. 微信web开发者工具下载地址
  9. 解决Could not find metadata org.apache.maven.pluginsmaven-archetype-pluginmaven-metadata.xml in
  10. 通信原理(1)基带传输