Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

a watery problem

Posted by KatrineYang at 2016-09-09 11:37:09 on Problem 1317
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int toint(char c){
	if(c == '_') return 0;
	if(c == '.') return 27;
	return c-'a'+1;
}

char tochar(int n){
	if(n == 0) return '_';
	if(n == 27) return '.';
	return (char)(n+'a'-1);
}

int main() {
	int k;
	char str[1000];
	while(1){
		scanf("%d", &k);
		if(k == 0) break;
		scanf("%s", str);
		int n = strlen(str);
		int ans[1000];
		for(int i = 0; i < n; i++){
			ans[(k*i)%n] = (toint(str[i])+i)%28;
		}
		for(int i = 0; i < n; i++){
			printf("%c", tochar(ans[i]));
		}
		printf("\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator