一道竞赛题,但是应该不难
Waterloo ACM Programming Contest Oct 5, 1996
这里是链接
http://acm.hit.edu.cn/ojs/show.php?Proid=1536&Contestid=0
我的代码, 如果有空,麻烦大家帮我看看,谢谢了
#include <stdio.h>
#include <stdlib.h>
#define SIZE 27
void scan_data (char*, int);
void scan_and_change_text (char*, char*);
void print_result (char*, int);
int main (void)
{
char org_alp[SIZE]; /*原始字母表*/
char sub_alp[SIZE]; /*替换后的字母表*/
scan_data (org_alp, SIZE);
scan_data (sub_alp, SIZE);
print_result(sub_alp, SIZE);
print_result(org_alp, SIZE);
scan_and_change_text (org_alp, sub_alp);
return 0;
}
/*
*define scan_data
*该函数用于读取数据
*/
void scan_data (char* w_arr, int size)
{
int i;
for (i = 0; i <= size - 1; i++)
{
scanf ("%c", &w_arr[i]);
}
}
/*
*define scan_and_change_text
*该函数用于读取并加密(改变)text
*/
void scan_and_change_text (char *org_alp, char *sub_alp)
{
char c;
int i,counter = 0;
while( (scanf ("%c", &c) ) != EOF)
{
for (i = 0; i <= SIZE - 2; i++)
{
if (c == org_alp[i])
{
c = sub_alp[i];
break;
}
}
putchar(c);
counter++;
if (counter == 64)
printf ("\n");
if (c == '\n')
counter = 0;
}
printf ("\n");
}
/*
*define print_result
*该函数用于打印最后的结果
*第一个参数为数组首元素的地址,第二个参数为数组大小
*/
void print_result (char *w_arr, int side)
{
int i;
for (i = 0; i <= side - 1; i++)
{
printf ("%c", w_arr[i]);
}
}