腾讯2018暑期实习生招聘在线笔试之字符串操作
2017-04-08 23:22
531 查看
某互联网公司2017年暑期实习生招聘软件开发在线笔试时间是2017年4月3日19:00至21:00(北京时间),题目主要是30道不定向选择题(1小时),2道简答题,2道在线编程题(1小时),题目涉及范围很广,包括C++、网络、算法等基础知识。其中,在线编程题语言有C、C++、C#、Java、Python、PHP、JavaScript可以选择!
*******************************************************************
在线编程题:
编写代码,接收从屏幕输入的长度为16字节的整数倍的字符串,回车后,按示例格式排版输出。
屏幕输入(均为可见字符):
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl
屏幕输出(斜体部分是格式说明,不要在结果里输出)
*********************************************************************
Python实现代码(使用python 2.7.10解释运行):
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
C#实现代码(使用.NET 4编译运行):
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
代码实现截图:
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
//参考文章
http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html
http://www.cnblogs.com/maanshancss/p/4074524.html
http://www.cnblogs.com/zhangqs008/archive/2012/02/01/2341078.html
http://blog.csdn.net/wangshubo1989/article/details/46905881
*******************************************************************
在线编程题:
编写代码,接收从屏幕输入的长度为16字节的整数倍的字符串,回车后,按示例格式排版输出。
屏幕输入(均为可见字符):
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl
屏幕输出(斜体部分是格式说明,不要在结果里输出)
*********************************************************************
Python实现代码(使用python 2.7.10解释运行):
#python代码示例处理正常,但是可能存在缺少特殊情况的考虑,欢迎在下面批评指出 inputstr=raw_input() lineCount=len(inputstr)//16 #输入行数 lineIndex=0 # copyright @ Cnblogs DHUtoBUAA while lineIndex<lineCount: outputStr="" linestr=hex(lineIndex*16+16) outputStr+=linestr[2:].zfill(8) #zfill方法用来给字符串前面补0 outputStr+=" " #字符串截取:当使用以冒号分隔的字符串,python返回一个新的对象,结果包含了以这对偏移标识的连续的内容 #左边的开始是包含了下边界,而取到的最大范围不包括上边界 for x in inputstr[lineIndex*16:lineIndex*16+8]: outputStr+=hex(ord(x))[2:]+" " outputStr+=" " for x in inputstr[lineIndex*16+8:lineIndex*16+16]: outputStr+=hex(ord(x))[2:]+" " outputStr+=" " outputStr+=inputstr[lineIndex*16:lineIndex*16+16] print(outputStr) lineIndex+=1
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
C#实现代码(使用.NET 4编译运行):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string InputStr = Console.ReadLine(); //屏幕输入 int lineCount = InputStr.Length / 16; //copyright @ cnblogs DHUtoBUAA for(int lineIndex=0;lineIndex<lineCount;lineIndex++) { string output=""; int line = (lineIndex + 1) * 16; output+=Convert.ToString(line, 16).PadLeft(8,'0'); output += " "; for(int charIndex=0;charIndex<16;charIndex++) { char temp = InputStr[charIndex + 16 * lineIndex]; // Get the integral value of the character. int value = Convert.ToInt32(temp); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:x}", value); output += hexOutput; output += " "; if(charIndex==7) output += " "; } //截取 Substring(Int32, Int32):子字符串从指定的字符位置开始且具有指定的长度, // 提取字符串中的第i个字符开始的长度为j的字符串 output += " "; output += InputStr.Substring(lineIndex * 16,16); Console.WriteLine(output); } Console.ReadKey(); } } }
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
代码实现截图:
**** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
//参考文章
http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html
http://www.cnblogs.com/maanshancss/p/4074524.html
http://www.cnblogs.com/zhangqs008/archive/2012/02/01/2341078.html
http://blog.csdn.net/wangshubo1989/article/details/46905881
相关文章推荐
- [2016腾讯暑期实习在线笔试题]最长回文字符串
- 2015腾讯暑期实习招聘在线笔试(问答题)
- 【每日面试题】2012年腾讯暑期实习生招聘笔试附加题1
- 2017腾讯-暑期实习生在线测试-16进制字符串转换
- 2018腾讯实习生招聘笔试题
- 华为、腾讯实习生招聘笔试、面试经验
- [笔试编程题] 腾讯2017暑期实习生编程题-java
- 2017腾讯实习生招聘笔试编程题
- 网易互娱2017实习生招聘在线笔试第一场题目解析
- 腾讯2014年实习生招聘笔试面试经历
- 网易游戏2016实习生招聘在线笔试之连连看
- 腾讯-模拟考-技术研发类-移动客户端开发-2018实习生招聘
- 腾讯2012.4.25实习生招聘笔试题
- 腾讯2012.4.25实习生招聘笔试题(2)
- 百度笔试2012暑期实习生招聘(java)
- 2016腾讯实习生在线笔试
- JAVA动态规划(三)--最长回文字符串(可删除中间字符)【腾讯2016实习生笔试题】
- 2018网易游戏雷火盘古实习生招聘笔试真题
- 微软2012暑期实习生校园招聘笔试题
- 易互娱2017实习生招聘在线笔试第一场题目1 : 电子数字