2857 - ASCII码2
<span style="color:#000000;font-weight:normal;font-style:normal;font-size:10.5000pt;font-family:'微软雅黑';background:#F5F5F5;">相信大家一定都知道大名鼎鼎的ASCII码,这次给你的任务是输入数字(表示ASCII码),输出相对应的字符信息。</span>
题目输入
本题有多组测试数据。
第一行为一个整数T(1<=T<=20)。
这些整数不会小于32(32为空格)。
题目输出
在一行内输出相应的字符信息。(注意不要输出任何多余的字符)
当其中有任何一个整数小于32时,输出“ERROR!“
输入/输出样例
题目输入
13 72 101 108 108 111 44 32 119 111 114 108 100 33 1 13
题目输出
Hello, world! ERROR!
提示
作者:梁青青
C语言解答
#include <stdio.h> #include <malloc.h> int main() { int T; int *n; int tag = 0; while (scanf("%d", &T) != EOF) { tag = 0; n = (int *)malloc(T*sizeof(n)); for (int i = 0; i < T; i++) { scanf("%d", &n[i]); if (n[i] < 32) tag = 1; } if (tag == 1) printf("ERROR!\n"); else { for (int i = 0; i < T; i++) { printf("%c", n[i]); } printf("\n"); } } return 0; }
C++解答
#include<stdio.h> int main() { int t; while(scanf("%d",&t)!=EOF) { int a[20]; int ok=0; for (int i=0;i<t;i++) { scanf("%d",&a[i]); if (a[i]<32) ok=1; } if (ok) printf("ERROR!\n"); else { for (int i=0;i<t;i++) printf("%c",a[i]); printf("\n"); } } return 0; }
提示
作者:梁青青