• ACM/ICPC ZOJ1006-Do the Untwist 解题代码


    #include <iostream>
    #include <string>
    #include <stdlib.h>
    using namespace std;
    int main()
    {
    	string array[30][2];
    	string a,b;
    	int t=0;
    	while( cin >> a )
    	{
    		if ( a == "0" )
    		{
    			break;
    		}
    		else
    		{
    			cin >> b;
    		}
    		array[t][0] = a;
    		array[t][1] = b;
    		t++;
    	}
    
    	for ( int i = 0; i < t; i++ )
    	{
    		const char *p = array[i][0].c_str();
    		int k = atoi(p);
    		int len = array[i][1].size();
    		int *ciphercode = new int[len];
    		for ( int s = 0; s <len; s++ )
    		{
    			if ( array[i][1][s] == '.')
    			{
    				ciphercode[s] = 27;
    			}
    			else if ( array[i][1][s] == '_')
    			{
    				ciphercode[s] = 0;
    			}
    			else
    			{
    				ciphercode[s] = array[i][1][s] - 96;
    			}
    		}
    
    		int *plaincode = new int[len];
    		for ( int s = 0; s < len; s++ )
    		{
    			int pt = ( k*s )%len;
    			plaincode[pt] = (ciphercode[s] + s)%28;
    			
    			//cout <<pt <<" "<< plaincode[pt] << " ";
    		}
    		//cout << endl;
    
    		char *plaintext = new char[len];
    		//cout << plaintext << endl;
    		for ( int s = 0; s < len; s++ )
    		{
    			if (plaincode[s] == 0 )
    			{
    				plaintext[s] = '_';
    			}
    			else if (plaincode[s] == 27 )
    			{
    				plaintext[s] = '.';
    			}
    			else
    			{
    				plaintext[s] = plaincode[s] + 96;
    			}
    		}
    		//string resut(plaintext);
    		for ( int m = 0; m < len; m++ )
    		{
    			cout << plaintext[m];
    		}
    		cout << endl;
    		delete [] plaincode;
    		delete [] plaintext;
    		delete [] ciphercode;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    jade反编译,把html编译成jade
    runtime环境下的jade
    jade过滤器
    jade-render-renderFile
    【[USACO17DEC]Standing Out from the Herd】
    bzoj 1396: 识别子串
    bzoj 4327:JSOI2012 玄武密码
    hihocoder 后缀自动机四·重复旋律6
    hihocoder 后缀自动机四·重复旋律7
    【[CTSC2012]熟悉的文章】
  • 原文地址:https://www.cnblogs.com/2011winseu/p/3178624.html
Copyright © 2020-2023  润新知