标签:style blog class c code java
1 #include <stdio.h> 2 #include <stdlib.h> 3 int min(int x,int y) 4 { 5 if(x < y) 6 return x; 7 else 8 return y; 9 } 10 int main() 11 { 12 char *str = NULL,c,*res = NULL; 13 int n,i,j,t; 14 scanf("%d",&n); 15 str = malloc(sizeof(char)*n); 16 res = malloc(sizeof(char)*n); 17 for(i = 0; i < n; i++) 18 { 19 getchar(); 20 scanf("%c",&c); 21 str[i] = c; 22 } 23 24 i = 0; //头部索引 25 j = n-1; //尾部索引 26 t = 0; 27 while(i <= j) 28 { 29 if(str[i] < str[j]) 30 res[t++] = str[i++]; 31 else if(str[i] > str[j]) 32 res[t++] = str[j--]; 33 else if(str[i] == str[j]) // 分析两者相等的情况 34 { 35 int left = i,right = j; 36 while(str[left] == str[right] && left < right) //如果下一位继续相等继续比较下一位 37 { 38 left++; 39 right--; 40 } 41 if(str[left] < str[right] || left == right) //如果头部的值小或者比较到两者的索引相等了此时这个串中间是对称的了,前后均可! 42 { 43 res[t++] = str[i++]; 44 45 } 46 47 else if(str[left] > str[right]) //右边的小取右边 48 { 49 res[t++] = str[j--]; 50 } 51 52 return 0; 53 }
Best Cow Line 解题报告,布布扣,bubuko.com
标签:style blog class c code java
原文地址:http://www.cnblogs.com/programmer-cjr/p/3718062.html