#include <iostream> #include <string.h> using namespace std; char * Grial(char *str,int x) { int j = x-1; int i = 0; char *p = str+j; char *q = str; char temp; while(i<j) { while(*p!='0') { p--; j--; } while(*q!='1') { q++; i++; } if(i<j) { temp = *p; *p = *q; *q = temp; } } return str; } int main() { char s[]="0101"; cout<<Grial(s,strlen(s))<<endl;//0011 return 0; }
时间: 2024-11-10 21:52:40