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

      

  • 相关阅读:
    重写不受限制
    类的向上转型(安全)向下转型(不安全)
    类的继承之构造函数和析构函数的顺序
    父类和子类的截断现象
    派生类重写方法
    运算符重载总结(大全)
    运算符重载方法3
    运算符重载方法2
    Shell基础编程
    TCP Wrappers(简单防火墙)---限制IP登录ssh
  • 原文地址:https://www.cnblogs.com/2011winseu/p/3178624.html
Copyright © 2020-2023  润新知