C/C++の宿題を片付け ..
[
2ch
|
▼Menu
]
■コピペモード
□
スレを通常表示
□
オプションモード
□このスレッドのURL
■項目テキスト
415:デフォルトの名無しさん 07/09/27 05:56:53 >>396 #include <stdio.h> #include <stdlib.h> #include <ctype.h> struct node { char element; struct node *next; }; int check(struct node *p, struct node *mid) { int i, j, n = mid->element - '0'; struct node *temp; for(i=0, temp = p; temp!=mid; i++, temp=temp->next); if(i!=n) return 0; for(i=0; i<n; i++, temp=temp->next) if(temp->next==NULL) return 0; for(i=0; i<n; i++, p=p->next) { for(temp=mid, j=0; j<n-i; j++, temp=temp->next); if(p->element != temp->element) return 0; } return 1; } 416:デフォルトの名無しさん 07/09/27 05:59:16 続き struct node* mirror_image(struct node *list) { struct node *p, *buf = NULL, *temp, *ret = (struct node*)malloc(sizeof(struct node)); int max = 0; ret->next = NULL; for(p=list->next; p!=NULL; p=p->next) { for(temp=p->next; temp!=NULL; temp=temp->next) { if(isdigit(temp->element) && temp->element - '0' > max) { if(check(p, temp)) { buf = p; max = temp->element - '0'; } } } } if(buf) { int i, l = 2 * max + 1; for(i=0, temp = ret; i<l; i++, buf = buf->next) { temp = temp->next = (struct node*)malloc(sizeof(struct node)); temp->element = buf->element; } temp->next = NULL; } return ret; }
次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
レスジャンプ
mixiチェック!
Twitterに投稿
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch
5291日前に更新/230 KB
担当:undef