• 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;
    }
    

      

  • 相关阅读:
    windows-DLL注入
    HDU 2148 Score
    HDU 2133 What day is it
    HDU 2112 HDU Today
    HDU 2187 悼念512汶川大地震遇难同胞——老人是真饿了
    HDU 2124 Repair the Wall
    HDU 2117 Just a Numble
    HDU 2114 Calculate S(n)
    HDU 2115 I Love This Game
    HDU 2104 hide handkerchief
  • 原文地址:https://www.cnblogs.com/2011winseu/p/3178624.html
Copyright © 2020-2023  润新知