京东2016年校招笔试题
来源:互联网 发布:unity3d汽车行走代码 编辑:程序博客网 时间:2024/05/17 14:28
1、空格替换问题
要求将空格替换为指定的字符串,在原数组的基础上面替换。
import java.util.Scanner;public class Main { public static char[] replaceString(char[] str,int oldlen,char[] replaces){ int j = str.length-1; for (int i = oldlen-1; i >= 0; i--) { if (str[i]!=' ') { str[j] = str[i]; j--; }else { for (int k = replaces.length-1; k >= 0 ; k--) { str[j] = replaces[k]; j--; } } } return str; } public static void replace(String str, String replace){ if (str==null) { return; } if(str.length()==0||str.length()>50){ return; } if (replace==null) { return; } if(replace.length()==0||replace.length()>10){ return ; } char[] replaces = replace.toCharArray(); String[] strs = str.split(" +"); //System.out.println(strs.length); //原始长度-空格数+替换长度*空格数 char result[] = new char[str.length()-(strs.length-1)+(strs.length-1)*replaces.length]; System.arraycopy(str.toCharArray(), 0, result, 0, str.length()); replaceString(result,str.length(),replaces); for (int i = 0; i < result.length; i++) { System.out.print(result[i]); } } public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { String str, replace; str = cin.nextLine(); replace = cin.nextLine(); //System.out.println(str+" "+replace); replace(str,replace); } //System.out.println(replaceString("You are the best".toCharArray(),16,"123".toCharArray())); //System.out.println(replaceString("a b c d","abcd")); }}
2、跳楼梯问题
每次只能跳一格或者两格,从第一个格跳起走,即当只有一个梯子时,为0。
import java.util.Scanner;public class Main { public static int kip(int m){ int sum=0; if (m==1) { return sum; } if (m==2) { return 1; } if (m==3) { return 2; } int first = 1; int secord = 2; for (int i = 4; i <= m; i++) { sum = first+secord; first = secord; secord = sum; } return sum; } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int num = cin.nextInt(); for (int i = 0; i < num; i++) { int m = cin.nextInt(); System.out.println(kip(m)); if (num-1==i) { break; } } }}
0 0
- 京东2016年校招笔试题
- 京东2016笔试题
- 京东2016笔试题
- 京东2016笔试题
- 京东2017年校招笔试题
- 京东2016笔试编程题
- 【笔试练习】腾讯2016笔试题
- 腾讯2016年校招实习笔试题
- 阿里巴巴2016年校招笔试题(1)
- 滴滴出行2016年校招笔试题整理
- 京东2016校园招聘笔试题
- 京东2016笔实习生在线笔试题
- 京东2016笔试题,小东复习
- 京东2016笔试题 小东拉票
- 京东2016研发工程师笔试题【年终奖】
- 京东2016年算法工程师笔试题
- 京东-链笔试题
- 京东-链笔试题
- 安卓应用安全防护
- VMWare安装苹果系统及相关问题处理
- PHP版本5.*的BUG
- LT8912 业界新突破 MIPI转HDMI、MIPI转MHL、MIPI转LVDS最强转接IC
- [转]正则表达式
- 京东2016年校招笔试题
- English in September
- jquery操作复选框(checkbox)的12个小技巧总结
- idea languagelevel问题
- 南阳oj_(31)5个数求最值
- 介绍一个轻量级iOS安全框架:SSKeyChain
- OSG中的示例程序简介
- MongoDB数据库建立连接
- DataSet用法详细