The above is subject Requirements: time complexity is O (n), space complexity is O (1), It is my code:
#include Int main () { Int a, b, c, d, I; char ch; A=b=c=d=0; While ((ch=getchar ())! ) ='\ n'{ If (ch=='a') +; Else if (ch=='b') b++; Else if (ch=='c') c + +; Else if (ch=='d') d++; } for(i=0; Ifor(i=0; Ifor(i=0; Ifor(i=0; IPrintf (" \ n "); return 0; }
CodePudding user response:
#include #include #include Int main () { Int a [4]={0}, I=0; Char ch, * p, * q; While ((ch=getchar ())! ) ='\ n'A [ch - 'a'] + +; Q=p=malloc (a [0] a [2] + [1] a + + a + 1) [3]. While (I & lt; 4) { Memset (q, 'a' + I, a [I]); Q +=a [i++]; } * q='\ 0'; Puts (p); Free (p); return 0; }
Half after the front half can shorten a bit, but don't know the upper limit of data size is not good ah, had to figure out a way to reduce the output frequency, output only one try,