IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> 挑战C++服务器开发岗笔试题 -> 正文阅读

[C++知识库]挑战C++服务器开发岗笔试题

最近指导了一位同学,他获得某公司的C++服务器开发岗的笔试机会。要求线上答题,是开放式答题,只要在规定时间内把题目做好提交即可。和我沟通指导后,很顺利的通过了笔试。现在把整个指导过程记录一下,以作分享。

笔试题原文

In this project, we want to create a cross reference generator. We assume that we have a file of text(GNU GENERAL PUBLIC LICENSE is a good candidate). We want to read in the file and print out an alphabetized list of all the words in the file, using the following format:

WORD

NUMBER OF OCCURRENCES

LINES THAT THE WORD APPEARED ON

You may assume that your cross-reference generator is not case-sensitive, that is the words “Did” and “did” are the same. And again you can use Pseudo Code (some sample pseudo code is on Page 4) or Lua?if you can complete in time. At least explain your idea.

For example, running the cross-reference generator with the first two lines from the poem
Jabberwocky by Lewis Carroll produce the following:

Line 1 Twas brillig and the slithy toves
Line 2 Did gyre and gimble in the wabe

Word

Count

Lines

and

2

1 ??2

brillig

1

1

did

1

2

gimble

1

2

gyre

1

2

in

1

2

slithy

1

1

the

2

1 ??2

toves

1

1

twas

1

1

wabe

1

2

Total

13

以上就是全部问题。

真题分析

题目其实并不很难,技术经理出这个题目,大概是想考核两个“技术点”。

第一点,就是怎样处理英文文档的项目需求。国内程序员,大部分的英语水平非常一般,如果能保持高中生的英语水平,已经算是程序员中的“佼佼者”了,但是对于程序员老鸟,这并不妨碍处理英文文档。直接使用网络工具,加项目理解,基本上就能理解了。推荐工具,使用有道词典。需要注意的是,翻译工具翻译后只能作为参考,需要程序员结合语境进行“二次翻译”。

第二点,就是使用C++解决问题的能力。这个题目,难度并不大,但是如果对C++的各种基础容器不是很熟悉的话,直接使用C语言“裸写“,可能会导致时间上不够用,最后感叹这个题自己会做,只是出了点小问题,没有做完,没有做好。

真题解答

#include <iostream>
#include <list>	
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

struct Node {
	string word;
	int count = 0;
	vector<int>lines;

	bool operator==(const Node& other)const {
		return  _stricmp(word.c_str(), other.word.c_str()) == 0;
	}
	friend ostream& operator<<(ostream &out, Node &word)  {
		out << setw(10) <<std::left  << word.word << "\t" << word.count << "\t";
		for (int i = 0; i < word.lines.size(); i++) {
			out << word.lines[i] << "   ";
		}
		return out;
	}
};

bool wordNodeCompare(Node& node1, Node& node2) {
	return  _stricmp(node1.word.c_str(), node2.word.c_str()) < 0;
}

int main(void) {
	ifstream fin;
	string line;
	list<Node> wordList;
	int lineNumer = 0;
	int count = 0;
	const char* dStr = " ,.'-\"()1234567890";

	fin.open("test.txt");
	while (!fin.eof()) {
		getline(fin, line);
		lineNumer++;
		char* tmpLine = new char[line.length() + 1];
		strcpy(tmpLine, line.c_str());
		char* p = strtok(tmpLine, dStr);
		while (p) {
			Node word;
			word.word = p;
		
			auto it = std::find(wordList.begin(), wordList.end(), word);
			if (it != wordList.end()) {
				it->count++;
				if (std::find(it->lines.begin(), it->lines.end(), lineNumer) == it->lines.end()) {
					it->lines.push_back(lineNumer);
				}
			}
			else {
				word.count = 1;
				word.lines.push_back(lineNumer);
				wordList.push_back(word);
			}

			p = strtok(NULL, dStr);
		}
	}

	wordList.sort(wordNodeCompare);


	cout << setw(10) << std::left << "Word" << "\tCount\tLines" << endl;
	cout << "----------------------------------------------------" << endl;
	count = 0;
	for (auto it = wordList.begin(); it != wordList.end(); it++) {
		cout << *it << endl;
		count += it->count;
	}
	cout << "----------------------------------------------------" << endl;
	cout << setw(10) << std::left << "Total" << "\t" << count << endl;
	return 0;
}

?

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-07-05 23:22:06  更:2022-07-05 23:23:52 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/12 8:51:15-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码