6-30 Read Esc Chars (30分)(函数)

Esc characters are represented as \x in C string, such as \n and \t.
Function read_esc_chars() reads a line that may contains esc character representations from the standard input and parses all those esc character representations into esc characters.
For example, a string:
This is \t a test.
will be converted as:
This is a test.
There is a tab between is and a.
Your function should be able to recognize esc characters below: \n
\r
\t
\b
And all other characters below 0x20 will be presented as:
\hh
where hh is the hexadecimal of the value, all letters in capital. For a value below 0x10, a leading 0 is needed to keep two positions. And as a C string, 0x00 will not be part of the string but the terminator.
函数接口定义:
int read_esc_char(char *line, int len);
line is the place that can hold the string read from user’s input.
len is the size of line.
The function reads a whole line from the standard input and returns number of characters in the converted string. If the inputed line is longer than the place, only the characters that can be safely placed in the place can be read in.
裁判测试程序样例:
#include <stdio.h>
int read_esc_char(char line, int len);
static const LINE_LEN = 80;
int main()
{
char line[LINE_LEN];
printf("%d\n", read_esc_char(line, LINE_LEN));
printf("%s\n", line);
}
/
请在这里填写答案 */
输入样例:
hello\tworld
输出样例:
11
hello world
There is a tab between hello and world.

int read_esc_char(char *line, int len){char fh;int t=0,sum;while(1){sum=0;fh=getchar();if(fh=='\n'||t>=len-1) break;else if(fh=='\\'){fh=getchar();if(fh=='b'){*(line++)='\b';}else if(fh=='t'){*(line++)='\t';} else if(fh=='n') {*(line++)='\n';}else if(fh=='r') {*(line++)='\r';}else {sum+=(fh-48)*16;fh=getchar();if(fh>='0'&&fh<='9') sum+=(fh-48);else if(fh>='A'&&fh<='F') sum+=(fh-55);else if(fh>='a'&&fh<='f') sum+=(fh-87);fh=sum;*(line++)=fh;}}else {*(line++)=fh;}t++;}*line='\0';return t;
}

//1.line的容量是80,其中’\0’也占一个位置所以最多装79;
//2.遇到其他以’‘打头的控制字符(除\t\n\r\b以外)也要将其转化成只占一个字节的东西
//(如:输入当中遇到\13,那么要将其转化为0x20以下的除tnrb外的控制字符,转化的准确度似乎没有做严格要求?)
//3.如果输入的是控制字符本身(即:’/t’or’^S’而非/t or /13)那么不做任何处理直接塞入line数组中即可。
//其他:第一个测试点大概与tnrb的转化有关,第二个测试点和其他控制字符的转化有关(\13,\0C等),第三个测试点判断line下标是否越界(?)。
//一个槽点,对输出内容的检测不是很严谨,用"%s"读入也可过关(即,题目hello\t world,输出6 hello ,也是可以的)。

6-30 Read Esc Chars (30分)(函数)相关推荐

  1. 5.2.4 js循环小练习02 6 做学院评奖系统​ 如果数学成绩大于80分并且语文成绩大于80分,获奖学金500元。​如果数学小于30并且语文小于30分,输出重修。 两个数a、b,如果a能被b整除

    文章目录 1 做学院评奖系统​ 如果数学成绩大于80分并且语文成绩大于80分,获奖学金500元.​ 如果数学小于30并且语文小于30分,输出重修. 2 两个数a.b,如果a能被b整除或a加b大于100 ...

  2. php k线15分钟 30分钟,15分钟30分钟K线战法

    A.一种利用均线,你在15分钟K线图上设置一根21天均线及一根5天均线,当你看到5天上穿21天均线时那就是买入信号:卖出方法有两种:一般情况下,看到5天均下穿21天均线就要坚决离场:特殊情况下,如该股 ...

  3. 杨杰matlab神经网络30例,MATLAB神经网络30例

    实例1 BP神经网络在非线性函数拟合中的应用1 1.1 理论基础1 1.1.1 BP网络概述1 1.1.2 BP神经网络的MATLAB函数2 1.2 非线性函数拟合方法6 实例2 主元BP神经网络在股 ...

  4. java 时间取整 不满30分钟的算整点,大于30分钟的算30分钟

    java 时间取整 不满30分钟的算整点,大于30分钟的算30分钟 ```java public class Test { /** * @param args */ public static voi ...

  5. ACMNO.3 有三个整数a b c,由键盘输入,输出其中的最大的数。 输入 一行数组,分别为a b c 输出 a b c其中最大的数 样例输入 10 20 30 样例输出 30

    基于平台Dev-C++ 5.11 题目描述 有三个整数a b c,由键盘输入,输出其中的最大的数. 输入 一行数组,分别为a b c 输出 a b c其中最大的数 样例输入 10 20 30 样例输出 ...

  6. 在猜年龄的基础上编写登录、注册方法,并且把猜年龄游戏分函数处理

    ''' 在猜年龄的基础上编写登录.注册方法,并且把猜年龄游戏分函数处理,如 2. 登录函数 3. 注册函数 4. 猜年龄三次函数 5. 选择三次奖品函数 ''' import random def u ...

  7. python编写一个判断完数的函数过程_第4章-30 找完数 (20分)python

    所谓完数就是该数恰好等于除自身外的因子之和.例如:6=1+2+3,其中1.2.3为6的因子.本题要求编写程序,找出任意两正整数m和n之间的所有完数. 输入格式: 输入在一行中给出2个正整数m和n(1 ...

  8. mysql 计算近30天总金额_MySQL数分实战:咖啡店精细化运营

    前期,我们已经对MySQL的增删改查.以及多种查询方式和窗口.视图进行了解学习.本次我们利用前期所积累的知识进行数据分析实战. 本次实战数据源来自: Superset​superset.workeri ...

  9. 判断一维对象数组的对象时间属性值是未来、今天、昨天、一周内、30天内、30天以前,并将该数组按照时间分类组成二维数组用于分时间段渲染

    //判断时间 let today = [] as any let yesterday = [] as any let aWeek = [] as any let aMonth = [] as any ...

最新文章

  1. mysql的常用函数
  2. 校园二手平台的开发和利用
  3. Linux一键安装PHP/JAVA环境OneinStack
  4. Lintcode 408 解题思路及c++代码
  5. mysql+monitor+下载_详解MySQL监控工具 mysql-monitor
  6. vue项目使用mint-ui库
  7. tornado 第一篇
  8. mysql生成app接口_Java实现app接口和Socket消息传递(10)java连接MySQL实现App登录接口...
  9. 父类作为方法的形参以及父类作为方法返回值
  10. 深入浅出面向对象分析与设计
  11. C++项目參考解答:累加求圆周率
  12. CVPR 2019 | 亮风台发布全球最大单目标跟踪数据集LaSOT
  13. jquery页面隐藏和展开之间切换
  14. Ubuntu 主题美化
  15. 编译原理-第一章:引论
  16. Windows Server AppFabric安装教程
  17. 批处理 %~dp0是什么意思
  18. 获取微信商户平台操作证书
  19. 华氏温度和摄氏温度的转换-C语言
  20. 使用SDK Manager给TX2刷机且安装OpenCV3.4.0、CUDNN7.6.5、Pytorch、Miniforge(含百度云安装包)

热门文章

  1. “非法“走线寝室自制智能NFC门禁
  2. android 手势密码锁 GestureLock
  3. python如何全网爬取_Python爬取全网热点榜单数据
  4. tomcat 配置 quercus记录:php使用连接池访问数据库
  5. 【FLASH存储器系列十一】Nand Flash芯片使用指导之一
  6. 大学生兼职平台设计思路
  7. 【机器人学习】分拣机器人运动学分析及轨迹规划仿真
  8. 通过U盘向服务器拷贝文件
  9. 基于51单片机智能鱼缸鱼塘养殖宠物喂食系统
  10. 互联网教育的现在和未来