POJ 1107:W's Cipher(模拟)

题面描述了一种加密的方式,让coder按照要求解密~

将字母分成三段,再将位置用数组储存~所谓的旋转其实就是右移~

#include"cstdio"
#include"iostream"
#include"cstring"
using namespace std;
int main()
{   int k1,k2,k3;
    while(scanf("%d%d%d",&k1,&k2,&k3)&&(k1||k2||k3))
    {   char arr[100],ans[120];
        cin>>arr;
        int num[3][120];
        int len=strlen(arr),len1=0,len2=0,len3=0;
        for(int i=0;i<len;i++)
        {   if(arr[i]<=‘i‘&&arr[i]>=‘a‘) num[0][len1++]=i;
            else if(arr[i]<=‘r‘&&arr[i]>=‘j‘) num[1][len2++]=i;
            else if(arr[i]<=‘z‘&&arr[i]>=‘s‘||arr[i]==‘_‘)num[2][len3++]=i;
        }
        for(int i=0;i<len1;i++)
        {   int key=i-k1;
            while(key<0) key+=len1;
            ans[num[0][i]]=arr[num[0][key]];
        }
        for(int i=0;i<len2;i++)
        {   int key=i-k2;
            while(key<0) key+=len2;
            ans[num[1][i]]=arr[num[1][key]];
        }
        for(int i=0;i<len3;i++)
        {   int key=i-k3;
            while(key<0) key+=len3;
            ans[num[2][i]]=arr[num[2][key]];
        }
        ans[len]=‘\0‘;
        cout<<ans<<endl;
    }
    return 0;
}

POJ 1107:W's Cipher(模拟)

时间: 2024-10-17 10:15:03

POJ 1107:W's Cipher(模拟)的相关文章

POJ 2996 &amp; 2993 国际象棋布局 模拟

Description Your task is to read a picture of a chessboard position and print it in the chess notation. Input The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white pl

POJ 3087 Shuffle&#39;m Up (模拟+map)

题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去. 现在输入s1和s2的初始状态 以及 预想的最终状态s12.问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1". 解题思路:照着模拟就好了,只是判断是否永远不能达到状态s12需要用map,定义map<

POJ 1027 The Same Game(模拟)

题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluster,同时cluster含有至少两个球),每次选择cluster中包含同色球最多的进行消除,每次消除完之后,上边的要往下移填满空的地方,一列上的球移动之前与之后相对位置不变,如果有空列,右边的列往左移动,每一列相对位置不变 . 思路 : 模拟......不停的递归..... 1 ////POJ 102

POJ 3282 Ferry Loading IV(模拟,队列)

题意   汽车通过渡船过河  渡船开始在左边   输入按车辆来的顺序输入河两岸的车   渡船每次运输的汽车的总长度不能超过渡船自己本身的长度  先来的车先走   求轮船至少跨河多少次才能将所有的车辆都运完 简单模拟  建两个队列  分别装左边的车  和右边的车   算出两边各至少需要运输多少次就行了 #include<cstdio> #include<cstring> #include<queue> using namespace std; int main() { i

POJ 2424 Flo&#39;s Restaurant 模拟

Flo's Restaurant Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2923   Accepted: 916 Description Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched her desk job and built her own restaurant. In the s

poj 1008:Maya Calendar(模拟题,玛雅日历转换)

Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, profes

POJ 3087 Shuffle&#39;m Up(模拟)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

poj 3087 Shuffle&#39;m Up (模拟过程)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

poj 3087 Shuffle&#39;m Up(模拟题)

Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6143   Accepted: 2880 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of