Time:06-11
CodePudding user response:
that is not the number of statistics/?
input string, calculate the escape character/n/a,/b/t the number of such as 12 d/nb#, enter # or to stop printing, o great god answer
/* - * Copyright (C), 1999-2019, mymtom. * _ * ____ _ _ ____ _ | | _ _____ _____ * | \ | | | | (_ _) _ \ | \ * | | | | | _ | | | | | | | | | _ | | | | | * | _ | _ _ - | | \ | _ | _ _ - | | \ () ___/| _ | _ | _ | * (____/* * vi: set ts=4 sw=4: *//* * C * @ file LetterCount.* @ brief, */#include Static int Unescape (int ch) {Int ret=0; If (' a '==ch) Ret='\ a'; Else if (' b '==ch) Ret='\ b; Else if (==ch 'f') Ret='\ f; Else if (==ch 'n') Ret='\ n'; Else if (==ch 'r') Ret='\ r; Else if (' t '==ch) Ret='\ t'; Else if (==ch 'v') Ret='\ n'; Return ret. } The static char * The escape (int ch, char * buf) {Int ret=0; If (\ 'a'==ch) Ret='a'; Else if (==ch \ b) Ret='b'; Else if (==ch \ f) Ret='f'; Else if (=='\ n' ch) Ret='n'. Else if (==ch \ r) Ret='r'. Else if (' \ t '==ch) Ret='t'. Else if (==ch \ v) Ret='v'; If (0==ret) {Buf [0]=ch; Buf [1]=0; } else {Buf [0]='\ \'; Buf [1]=ret; Buf [2]=0; } Return buf. } Int The main (int arg c, char * argv []) {int i; Int ch; Char buf [3]. Int count [256]={0}; While (EOF!=(ch=fgetc (stdin))) {If (' # '==ch) break; If (' \ \ '==ch) {Ch=fgetc (stdin); If (' # '==ch) break; Ch=unescape (ch); } The count [ch] + +; } For (I=0; I & lt; 256; I++) {If (count [I] & gt; 0 {Printf (" % s: 2.2%4 d \ n ", the escape (I, buf), the count [I]); } } return 0; }
Page link:https//www.codepudding.com/Backend/113001.html