C/C++の宿題を片付けます 96代目at TECH
C/C++の宿題を片付けます 96代目 - 暇つぶし2ch421:デフォルトの名無しさん
07/09/27 11:09:41
>>396 2/2
struct node *mirror_image(struct node *list) {
 char *cs = createcs(list);
 struct node *mirror = 0;
 int i, j, n, maxn_index = -1;
 for (i = 0; i < strlen(cs); i++) {
  if (!isdigit(cs[i])) continue;
  
  n = cs[i] - '0';
  if (i < n || (strlen(cs) - 1 - i) < n) continue; // 無理
  if (n < cs[maxn_index] - '0') continue; // 無駄
  for (j = 0; j < n; j++) { // n個チェック
   if (cs[i - (j + 1)] != cs[i + (j + 1)]) break;
  }
  if (n == j && cs[maxn_index] - '0' < n) maxn_index = i;
 }
 cs[maxn_index + (cs[maxn_index] - '0') + 1] = '\0';
 if (0 < maxn_index) {
  mirror = initclist(&cs[maxn_index - (cs[maxn_index] - '0')]);
 } else {
  mirror = (struct node *)calloc(1, sizeof(struct node));
 }
 free(cs);
 return mirror;
}


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch