Sample Input
1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5
Sample Output
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
问题链接:UVA458 The Decoder。
问题简述:观察样例总结编码规律,将输入的密文译成明文。
问题分析:观察试算的结果是,明文字符=密文字符-7。
程序说明:写程序,不是要写得简单,而是要写得极其简单。
大致思路:
刚开始一脸懵逼,后来想想是密码题嘛,而且题干也说了跟ASCII码有关,那么找到规律就发现很简单了。
不过要注意....所输入的字符串中'\n'是不用转换的!其他就转换后再以字符形式输出即可。
- #include <stdio.h>
- int main(void)
- {
- char c;
- while ((c = getchar()) != EOF)
- putchar((c == '\n') ? c : c-7);
- return 0;
- }
学到的点:
①密码水题——找规律!
②代码中的这个写法挺重要的。while((c=getchar())!=EOF) (C语言中输入的是字符串,而想要挨个对其中的字符进行处理的时候) 和putchar函数(C语言中输出单个字符的函数)。