sicily 1036. Crypto Columns

依然模拟:


#include<iostream>
#include<string>
using namespace std;
int main(){
	string mess,key;
	while(cin>>key&&key!="THEEND"){
		cin>>mess;
		int n1 = key.size() , n2 = mess.size(),count=0,cheng=n2/n1;
		int *pro = new int[n1];
		char *res = new char[n2+1];
		for(int i=0;i<n1;++i){
			int index = 0,min = 128;
			for(int j=0;j<n1;++j){
				if(key[j]<min){
					index = j;
					min = key [j];
				}
			}
			key[index]='a';
			pro[count] = index;
			++count;
		}
		count=0;
		for(int i=0;i<n1;++i){
			for(int j= pro[i]*cheng;j<(pro[i]+1)*cheng;++j){
				res[j] = mess[count];
				++count;
			}
		}
		for(int i=0;i<cheng;++i){
			for(int j= i;j<n2;j+=cheng)
				cout<<res[j];
		}
		cout<<endl;
		delete []pro;
		delete []res;
	}
	return 0;
}


你可能感兴趣的:(sicily 1036. Crypto Columns)