当前位置:   article > 正文

2019年4月3日华为实习生笔试第2题-合法去重移位排序输出_华为机试 合法去重移位排序输出

华为机试 合法去重移位排序输出

如果笔试成绩不理想,面试的时候会问,为什么没有做出来。还好我笔试后重新做了一遍!
题量很大,但是不是很难,这里需要注意四个输出:
(1)合法字符串去重输出(不是字符串中的字符去重,而是字符串去重)
(2)非法字符串直接输出
(3)合法字符串移位再输出
(4)在(3)的基础上排序输出
在这里插入图片描述
输入实例:(按Ctrl+Z结束输入)

abc
def
==
acd123
44234tjg
aga'-=
ad--s
abd
123
abcdef
12345678901234567890123456789012345678901234567890123
EDFG
SDFG
ABC
DEF
ccc
dd
asdfas
a*b=1
87&&^
==
234abs35
765rgfh4sd
1231
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

输出实例

abc def acd123 44234tjg abd 123 abcdef 12345678901234567890123456789012345678901
234567890123 EDFG SDFG ABC DEF ccc dd asdfas 234abs35 765rgfh4sd 1231
== aga'-= ad--s a*b=1 87&&^ ==
bca efd 23acd1 234tjg44 bda 231 efabcd 12345678901234567890123456789012345678901
231234567890 FGED FGSD BCA EFD ccc dd asasdf 4abs3523 765rgfh4sd 3112
12345678901234567890123456789012345678901231234567890 231 234tjg44 23acd1 3112 4
abs3523 765rgfh4sd BCA EFD FGED FGSD asasdf bca bda ccc dd efabcd efd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

如有错误的地方请指出,谢谢

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

void fun_moveBit(string &str)
{
	string tempStr;
	int moveBit = 10 % str.length();
	tempStr = str.substr(0, moveBit);
	str = str.erase(0, moveBit);
	str.append(tempStr);
}


int main()
{
	string str;
	vector<string> vecStr_OK;
	vector<string> vecStr_NO;
	while (cin >> str)
	{
		int flag = 1;
		string newStr;
		for (int i = 0; i < str.size(); i++)
		{
			//判断是否合法//一旦不合法就将标志位置0
			if (!(str[i] >= '0' && str[i] <= '9') && !(str[i] >= 'a' && str[i] <= 'z') && !(str[i] >= 'A' && str[i] <= 'Z'))
			{
				flag = 0;
				break;
			}
		}
		if (flag == 1)//OK
		{
			//去重
			if (find(vecStr_OK.begin(), vecStr_OK.end(), str) == vecStr_OK.end())
			{
				vecStr_OK.push_back(str);
			}
		}	
		else//No
			vecStr_NO.push_back(str);

	}

	
	//第1个输出
	for (int i = 0; i < vecStr_OK.size(); i++)
	{
		string tempStr;
		tempStr = vecStr_OK[i];
		cout << tempStr << " ";
	}
	cout << endl;

	//第2个输出
	for (int i = 0; i < vecStr_NO.size(); i++)
	{
		cout << vecStr_NO[i] << " ";
	}
	cout << endl;

	//第3个输出
	for (int i = 0; i < vecStr_OK.size(); i++)
	{
		fun_moveBit(vecStr_OK[i]);
		cout << vecStr_OK[i] << " ";
	}
	cout << endl;

	//第4个输出
	sort(vecStr_OK.begin(), vecStr_OK.end());
	for (int i = 0; i < vecStr_OK.size(); i++)
		cout << vecStr_OK[i] << " ";

	cout << endl;

	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/799853
推荐阅读
相关标签
  

闽ICP备14008679号