ACM_程序设计竞赛:贪心算法:字典最小序

来源:互联网 发布:python的布尔值 编辑:程序博客网 时间:2024/06/11 09:58
#include <stdio.h>#include <tchar.h>#include <queue>#include <iostream>using namespace std;const int N = 8;char chs[N+1] = "ADHCACBD";char* solve(char chs[]){    int start = 0, end = N - 1;    bool isLeft = false;    char dest[N];    while(start <= end) {        for(int i = 0; start + i < end; i ++)        {            if(chs[start + i] < chs[end - i])             {                isLeft = true;                break;            }            else if(chs[start + i] > chs[end -i])            {                isLeft = false;                break;            }            else                 continue;        }        if(isLeft)        {            dest[N-(end - start + 1)] = chs[start ++];            //putchar(chs[start ++]);        }        else        {            dest[N-(end - start + 1)] = chs[end --];            //putchar(chs[end --]);        }    }    return dest;}int main() {    char* result = solve(chs);    for(int i=0; i<N; i++)     {        putchar(result[i]);    }    cout<<endl;    return 0;}
0 0