华为2015机试题目汇总

本文汇总了华为2015年的机试题目,包括天数计算、字符串处理、输入法编码、完数查找、乘法口诀及字符串匹配等多元算法问题,适合编程爱好者和求职者进行练习和挑战。
摘要由CSDN通过智能技术生成

1、输入一行,输出一行,直到文件末尾,除去重复的数。

/*
STL解决
*/
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
void GetNoReplicates()
{
	string str;

	vector<int> result;
	vector<int>::iterator iter;

	while(cin>>str)
	{
		int i=0;
		int temp;
		while(str[i]!='\0')
		{
			temp=0;
			while(str[i]!='\0'&&str[i]!=',')
			{
				temp=10*temp+str[i]-'0';
				i++;
			}
			if(str[i]=='\0')
			{
                result.push_back(temp);
			    vector<int> copy;
				copy.push_back(result[0]);
				for(int j=1; j<result.size();j++)
				{
					iter=find(copy.begin(),copy.end(),result[j]);
					if(iter==copy.end())
					{
						copy.push_back(result[j]);
					}
				}
				for(int k=0;k<copy.size();k++)
				{
					if(k==copy.size()-1)
					{
						cout<<copy[k]<<endl;
					}
					else
					{
						cout<<copy[k]<<",";
					}
				}
				result.clear();
				break;
			}
			else
			{
				result.push_back(temp);
				i++;
			}
		}
	}
}
void main()
{
	GetNoReplicates();
}
/*
set记录排除集
*/
#include<iostream>
#include<string>
#include<set>
using namespace std;
void GetNoReplicates()
{
	int temp[4096];
	int result[4096];
	string str;
	int num;
	int j=0;
	memset(temp,0,sizeof(int)*4096);
	set<int> hash;
	while(cin>>str)
	{
		int i=0;
		int r=0;
		while(str[i]!='\0')
		{
			num=0;
			while(str[i]!='\0'&&str[i]!=',')
			{
				num=10*num+str[i]-'0';
				i++;
			}
			if(str[i]=='\0')
			{
				temp[j++]=num;
				result[r++]=temp[0];
				hash.insert(temp[0]);
				for(int k=1;k<j;k++)
				{
					if(0==hash.count(temp[k]))
					{
						result[r++]=temp[k];
						hash.insert(temp[k]);
					}
				}
				for(k=0;k<r;k++)
				{
					if(k==r-1)
						cout<<result[k]<<endl;
					else
						cout<<result[k]<<",";
				}
				j=0;
				hash.clear();
				break;
				
			}
			else
			{
				temp[j++]=num;
				i++;
			}
		}
	}
}
void main()
{
	GetNoReplicates();
}

2、天数问题

输入:MM-YYYY,MM为月份,YYYY为年份,例如:08-2014

输出:指定年份和月份的天数。例如,08-2014,对应输出为31。

#include<iostream>
#include<string>
using namespac
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值