题解 | #字符串排序#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
首先使用set将key去重存入 然后在后面补齐缺失的字母 使用dictionary将set作为key值,对应之前的正常字母表 然后把wrod直接可以字典中查询到对应的字母
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleAppTest
{
public static class Test
{
public static void Main()
{
string key = Console.ReadLine();
string word = Console.ReadLine();
char[] charKey = key.ToCharArray();
char[] charWord = word.ToCharArray();
HashSet<char> set = new HashSet<char>();
for (int i = 0; i < charKey.Length; i++)
{
set.Add(charKey[i]);
}
int k = 0;
while (set.Count < 26)
{
char temp = (char)('a' + k);
set.Add(temp);
k++;
}
List<char> list = set.ToList();
Dictionary<char,char> map = new Dictionary<char,char>();
int begin = 97;
for (int i = 0; i < set.Count; i++)
{
map.Add((char)(begin + i), list[i]);
}
for (int i = 0; i < charWord.Length; i++)
{
char temp = char.ToLower(charWord[i]);
}
Console.WriteLine(charWord);
}
}
}