您的位置:首页 > 其它

腾讯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解释运行):

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: