POJ1107 W's Cipher 简单模拟
2015-12-23 14:42
253 查看
POJ1107 W’s Cipher
Description
先是将字母和下划线分为三类a~i,j~r,s~z和‘_’; 然后,独立地交换每组的字母,例如:对于 “_icuo_bfnwhoq_kxert”,第一组符号有{i,c,b,f,h,e},位置分别为{2,3,7,8,11,17},假设k1=2;那么第一组符号顺序变为{h,e,i,c,b,f},不过在原字符串中占有的位置还是{2,3,7,8,11,17},然后第二组······第三组······
Sample Input
2 3 1
_icuo_bfnwhoq_kxert
1 1 1
bcalmkyzx
3 7 4
wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji
2 4 3
cjvdksaltbmu
0 0 0
Sample Output
the_quick_brown_fox
abcklmxyz
the_quick_brown_fox_jumped_over_the_lazy_dog
ajsbktcludmv
题解:
整理ing
AC_Code(cpp):
Description
先是将字母和下划线分为三类a~i,j~r,s~z和‘_’; 然后,独立地交换每组的字母,例如:对于 “_icuo_bfnwhoq_kxert”,第一组符号有{i,c,b,f,h,e},位置分别为{2,3,7,8,11,17},假设k1=2;那么第一组符号顺序变为{h,e,i,c,b,f},不过在原字符串中占有的位置还是{2,3,7,8,11,17},然后第二组······第三组······
Sample Input
2 3 1
_icuo_bfnwhoq_kxert
1 1 1
bcalmkyzx
3 7 4
wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji
2 4 3
cjvdksaltbmu
0 0 0
Sample Output
the_quick_brown_fox
abcklmxyz
the_quick_brown_fox_jumped_over_the_lazy_dog
ajsbktcludmv
题解:
整理ing
AC_Code(cpp):
#include<iostream> using namespace std; struct mychar { char character; int position; }; void Decrypted(char encrypted[], int k1, int k2, int k3) { char decrypted[100]=""; mychar char1[100]; mychar char2[100]; mychar char3[100]; int count1 = 0; int count2 = 0; int count3 = 0; int len = strlen(encrypted); for (int i = 0; i < len; i++) { if (encrypted[i] >= 's' || encrypted[i] == '_') { char3[count3].character = encrypted[i]; char3[count3].position = i; count3++; } else if (encrypted[i] >= 'j') { char2[count2].character = encrypted[i]; char2[count2].position = i; count2++; } else { char1[count1].character = encrypted[i]; char1[count1].position = i; count1++; } } for (int i = 0; i < count3; i++) { decrypted[char3[(i + k3) % count3].position] = char3[i].character; } for (int i = 0; i < count2; i++) { decrypted[char2[(i + k2) % count2].position] = char2[i].character; } for (int i = 0; i < count1; i++) { decrypted[char1[(i + k1) % count1].position] = char1[i].character; } cout << decrypted << endl; } int main() { int k1, k2, k3; char encrypted[100]=""; while (cin >> k1 >> k2 >> k3 && (k1 + k2 + k3)) { cin >> encrypted; Decrypted(encrypted, k1, k2, k3); } return 0; }
相关文章推荐
- 一个简单而经典的RTX51 Tiny应用实例
- jQuery Ajax
- Android 内存泄露分析
- js实现懒加载
- FastDFS的配置、部署与API使用解读(4)FastDFS配置详解之Client配置
- @ResponseBody中文乱码问题
- zabbix乱码
- 4、重新编译内核
- python 字符串操作
- 盘点 PHP 和 ASP.NET 的10大对比!
- FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码
- 3、debian8安装和处理
- 2、各种折腾,安装交叉环境的gcc和qt,测试c++和qt程序
- Android 自定义 View 浅析
- 肖特基二极管和普通二极管的区别
- js函数
- tomcat域名访问设置
- 解决 winedit 打开tex文件 reading error
- 解决 winedit 打开tex文件 reading error
- Asp.Net MVC BundleConfig文件合并、压缩,网站优化加速