HDU2000

自从那次校赛没过以后就一直没心思做题,现在连水题要注意的PE也交了6次再看了一份AC代码才想起来,多输出了空格再换行也是会PE的。
真的是代码打得太少了。

#include <cstdio>
#include <cstring>
#include <cstdlib>

void swap(char *s,int j){
    char temp = s[j];
    s[j] = s[j+1];
    s[j+1] = temp;
}

void Bubblesort(char *s){
    char temp = s[0];
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 2;j++){
            if(s[j] > s[j+1])
                swap(s,j);
        }
    }
}

int main(){
    //freopen("in.txt","r",stdin);
    char s[4];
    while(scanf("%s",s)!=EOF){
        //getchar();
        Bubblesort(s);
        for(int i = 0;i < 2;i++){
            printf("%c",s[i]);
            printf(" ");
        }
        printf("%c",s[2]);
        printf("\n");
    }
    //printf("\n");
    return 0;
}
posted @ 2015-12-03 15:04  sean10  阅读(194)  评论(0)    收藏  举报