[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
题目:
编写一个应用程序用来输入的字符串进行加密,对于字母字符串加密规则如下:
‘a’→’d’ ‘b’→’e’ ‘w’→’z’ …… ‘x’→’a’ ‘y’→’b’ ‘z’→’c’‘A’→’D’
‘B’→’E’ ‘W’→’Z’ …… ‘X’→’A’ ‘Y’→’B’ ‘Z’→’C’?
对于其他字符,不进行加密。
这道题目很久以前听说过,但是没咋会,现在看看倒是不一样了
根据字母顺序a、b、c、d、e、f、g…来看,每个加密后的字符串都是原来字符串在字母表里+3的;
那么怎么+3呢?
这里想到了用ASCII码的十进制来做,每个字符串都在ASCII码中有位置,
所以进行编写代码:
将输进的字符串存进变量里;
string str = Console.ReadLine();
接着用foreach遍历字符串里的每个字符;
foreach (var item in str)
判定,如果 item >= 'a' 并且 item <= 'w'时(大写同理),进行处理,
将加密后的整形字符,用num存起来,增加3之后用char显示转换后输出;
if (item >= 'a' && item <= 'w' || item >= 'A' && item <= 'W') { int num =
item; num += 3; Console.Write((char)num); }
判定后三个字母,如果 item >= 'x' 并且 item <= 'z'时(大写同理),进行处理,
将加密后的整形字符,用num存起来,减去23之后用char显示转换后输出;
else if (item >= 'x' && item <= 'z' || item >= 'X' && item <= 'Z') { int num =
item; num -= 23; Console.Write((char)num); }
再看题目最后一句,对于其他字符,不进行加密,直接输出;
else { Console.Write(item); }
编译运行结果如下;
源代码如下:
string str = Console.ReadLine(); foreach (var item in str) { if (item >= 'a'
&& item <= 'w' || item >= 'A' && item <= 'W') { int num = item; num += 3;
Console.Write((char)num); } else if (item >= 'x' && item <= 'z' || item >= 'X'
&& item <= 'Z') { int num = item; num -= 23; Console.Write((char)num); } else {
Console.Write(item); } }
制作不易,来个一键三连呀o(* ̄▽ ̄*)ブ