Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2014 -- CSC 2700 Section 01

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

week04/j/untwist.cpp

#include <iostream>
#include <cstring>
#include <string>

#define DEBUG if(false)
using namespace std;

char cipherText[100];
int plain[100];
		
int i, key, length, temp;
int moreToDo = 1;
		

void process()
{
	cin >> cipherText;
	length = strlen(cipherText);

	for(i=0; i<length; i++) 
	{
		if		(cipherText[i] == '_') temp = 0;
		else if	(cipherText[i] == '.') temp = 27;
		else	temp = cipherText[i] - 'a' + 1;

		plain[key*i % length] = (temp+i) % 28;
	}
	
	for(i=0; i<length; i++) 
	{
        if		(plain[i] == 0)	cout << "_";
		else if	(plain[i] == 27)cout << ".";
		else	 cout << (char)(plain[i] + 'a' - 1);
	}
	cout << endl;
}

int main()
{
	while(moreToDo) 
	{
		cin >> key;
            
		if(key != 0) process();
		else moreToDo = 0;
	}
	return 0;
}

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014