code formatter
来源:互联网 发布:手机改图软件 编辑:程序博客网 时间:2024/05/16 01:03
Some companies have special requirements for source code format, and it is also good for programmers to keep consistent code style. You are asked to write a simple code formatter for the company to help the poor programmers.
The first thing you need to do is to check whether the source code contains tabs (represented as the escape character ‘\t’), since different terminals have different ways to display tabs, it’s better not to use them, but replace them with spaces. The code formatter should replace each tab of the source code with 4(four) blank spaces.
Then you need to remove trailing spaces of the source file. Trailing spaces are one or more consecutive whitespaces right before the EOL (end of line, represented as the escape character ‘\n’), and they usually have no meaning in most programming language, so they can be safely removed.
Input
The input contains multiple test cases!
The first line is an integer N indicating the number of test cases. Each test case is the source which contains not more than 100 lines given to you to format. A single line containing only “##” marks the end of a test case.
Output
For each test case, output a log of the formatter in two lines of the following format:
A tab(s) replaced #B trailing space(s) removed Where #A is the number of tabs replaced and #B is the number of trailing spaces removed.
Sample Input
2
include
#
#
Sample Output
4 tab(s) replaced
22 trailing space(s) removed
0 tab(s) replaced
0 trailing space(s) removed
Note
In order to show the whitespaces precisely, all the characters in sample input are underlined. They are not the underscore character.
题意:统计空格,和tabs的个数,其中一个tabs相当于4个空格。
#include <cstdio>#include <cstring>using namespace std;char str[1010];int main(){ int n, len, i, tab, trail, j, ans; scanf("%d", &n); getchar();//抵掉回车 for (i = 0; i < n; ++i) { tab = 0; ans = 0; trail = 0; while (gets(str)) { if (strcmp(str, "##") == 0)//遇见##表明一个样例的结束 break; trail = 0; len = strlen(str); for (j = 0; j < len; ++j) { if (str[j] == '\t') { tab ++; trail += 4; continue; } else if (str[j] == ' ') { trail ++; continue; } trail = 0; } ans += trail; } printf("%d tab(s) replaced\n", tab); printf("%d trailing space(s) removed\n", ans); } return 0;}
- Code Formatter
- Code Formatter
- code formatter
- CCS4 eclipse code formatter
- zoj 2851 Code Formatter
- zoj 2851 Code Formatter
- z0j 2851 Code Formatter
- ZOJ 2851Code Formatter
- ZOJ 2851 Code Formatter
- Android Studio Eclipse Code Formatter
- zoj 1851 Code Formatter 模拟
- eclipse formatter.xml Code Templates
- eclipse code formatter 插件下载
- eclipse code template and code Formatter
- zoj 2851 Code Formatter 水题(1)
- codetemplate和code formatter的使用
- IDEA插件配置之Eclipse Code Formatter
- 【ZOJ 2851 zoj 2851 Code Formatter】+ 字符串
- CSS学习笔记1
- [LeetCode]Binary Search Tree Iterator
- 如何在linux环境下使用r语言
- win+caffe mnist实例运行(禁止转载)
- lintcode_100题
- code formatter
- python zio库的ctf常用函数
- 打印图形
- Maven管理项目时 使用package命令报错:There are test failures
- Angular项目构建指南 - 不再为angular构建而犹豫不决
- C++ list: How to erase a reverse iterator?
- 常用手机号,邮箱,用户名 ,昵称校验工具类
- 编写代码不生效,不进断点
- 深入分析Parquet列式存储格式