栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2635 Transposition Cipher

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2635 Transposition Cipher

#include<iostream>#include<cstdio>#include<memory.h>#include<queue>#include<cstdio>#include<algorithm>using namespace std;#define Clear(f, nr) memset(f, nr, sizeof(f))const int SIZE = 30;queue<int> q[SIZE];struct Node{ int id; char ch;}node[SIZE];bool cmp(Node a, Node b){ return a.ch < b.ch;}int main(){ int T; char line[10000], str[SIZE]; cin >> T; while(T --) { cin >> str; int len1 = strlen(str); for(int i = 0; i < len1; i ++) { node[i].id = i, node[i].ch = str[i]; while(!q[i].empty()) q[i].pop(); } getchar(); cin.getline(line, 10000); int len = strlen(line); sort(node, node + len1, cmp); bool vis[SIZE]; Clear(vis, 0); int tmp = len % len1; for(int i = 0; i < tmp; i ++) { vis[i] = 1; } int tot = len / len1; int mark = 0; int p = 0; for(int i = 0; p < len1; i = mark, p ++) { for(int j = i; j < i + tot; j ++) { q[node[p].id].push(line[j]); } mark = i + tot; if(vis[node[p].id]) { q[node[p].id].push(line[mark]); mark ++; } } while(1) { bool sign = 0; for(int i = 0; i < len1; i ++) { if(!q[i].empty()) { sign = 1; char tt = q[i].front(); cout << char(tt - 'A' + 'a'); q[i].pop(); } } if(!sign) break; } cout << endl; }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377690.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号