关闭

华为oj 字符串加密

112人阅读 评论(0) 收藏 举报
#include <iostream>
#include <string.h>
#include <map>
#define N 101
using namespace std;
std::map<char,int> character;
map<char,char> keydata;

void encrypt(char *key,char *data,char *en)
{
	character['a'] = 0;character['b'] = 0;character['c'] = 0;character['d'] = 0;character['e'] = 0;character['f'] = 0;character['g'] = 0;
    character['h'] = 0;character['i'] = 0;character['j'] = 0;character['k'] = 0;character['l'] = 0;character['m'] = 0;character['n'] = 0;
    character['o'] = 0;character['p'] = 0;character['q'] = 0;character['r'] = 0;character['s'] = 0;character['t'] = 0;character['u'] = 0;
    character['v'] = 0;character['w'] = 0;character['x'] = 0;character['y'] = 0;character['z'] = 0;
	map<char,int>::iterator iter = character.begin();
	while((*key) != '\0')
	{
		*key = tolower(*key);
		if(character[*key] == 0)
		{
			keydata[iter->first] = *key;
			character[*key] = 1;
			++iter;
			++key; 
		}
		else
		{
			++key;
		}
	}
	map<char,int>::iterator other = character.begin();
	for(;other != character.end();++other)
	{
		if(iter != character.end())
		{
		    if(other->second != 1)
			{
				keydata[iter->first] = other->first;
				++iter;
			} 
		} 
		
	}

    while((*data)!= '\0')
    {
	    if(isupper(*data))
		{
		   *en = toupper(keydata[tolower(*data)]); 
	       cout<<*en;
	    }
	    else
	    {
	    	*en = keydata[*data]; 
	        cout<<*en;
	    }
	    ++en,++data;
	} 
} 
int main()
{
    char key[N],data[N],en[N];
	while(cin>>key)
	{
	    cin>>data;
        encrypt(key,data,en);
        cout<<endl;
    }
	return 0;
} 

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27346次
    • 积分:2283
    • 等级:
    • 排名:第16356名
    • 原创:212篇
    • 转载:2篇
    • 译文:0篇
    • 评论:1条
    文章分类