要求:时间复杂度为O(n),空间复杂度为O(1)。
一下是我的代码:
include <stdio.h>
int main()
{
int a,b,c,d,i;
char ch;
a=b=c=d=0;
while((ch=getchar())!='\n')
{
if(ch=='a') a++;
else if(ch=='b') b++;
else if(ch=='c') c++;
else if(ch=='d') d++;
}
for(i=0;i<a;i++) printf("a");
for(i=0;i<b;i++) printf("b");
for(i=0;i<c;i++) printf("c");
for(i=0;i<d;i++) printf("d");
printf("\n");
return 0;
}[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
[url]https://www.douban.com/doulis...[/url]
[url]https://m.douban.com/doulist/...[/url]
[url]https://book.douban.com/douli...[/url]
[url]https://movie.douban.com/doul...[/url]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。