ZOJ
来源:互联网 发布:设计师用的软件 编辑:程序博客网 时间:2024/05/22 15:38
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.
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.
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.
2include <stdio.h>int main(){int a,b;while(scanf("%d %d",&a, &b) != EOF) printf("%d\n",a+b); }####
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 areunderlined. They are not the underscore character.
找字符的问题:注意是找末尾的“ ”,末尾一个‘\t’相当于四个空格
ac代码:
#include<stdio.h>#include<string.h>int main(){ int n,num1,num2,i,len,k; char a[200000]; scanf("%d",&n); getchar(); while(n--) { num1=num2=0; while(gets(a),strcmp(a,"##")!=0) { len=strlen(a); for(i=k=0;i<len;i++) { if(a[i]=='\t') { k+=4; num2++; continue; } if(a[i]==' ') { k++; continue; } k=0; } num1+=k; } printf("%d tab(s) replaced\n%d trailing space(s) removed\n",num2,num1); } return 0; }
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 如何查看Android API文档
- 最长对称子串
- AngularJs-指令<ng-**>
- Android Fragment 从源码的角度去解析(下)
- Android gradle build Thread(png-cruncher_7): Stream closed java.io.IOException: Stream closed
- ZOJ
- LintCode 解题记录17.4.27
- Androidstudio集成微信分享网页
- How Many Maos Does the Guanxi Worth
- getRealPath()和getContextPath()的区别
- 数据结构与算法--快速排序
- CCF NOI1071 Pell数列
- 编程序找出1000之内的所有完数
- 树中的最长路