目前分類:課業*School Work (148)
- Jun 07 Thu 2007 16:37
[課業] AI - 方陣
- Jun 07 Thu 2007 16:34
[課業] AI - 0607 minimax樹
- May 16 Wed 2007 15:24
[課業] AI - 股票
- May 10 Thu 2007 16:27
[課業] AI - 樹 ( DFS - 二元 )
- May 09 Wed 2007 14:09
[課業] AI人工智慧 (指標) 05/09
- May 09 Wed 2007 14:06
[課業] AI - 位億版本(指標)
- May 03 Thu 2007 10:01
[課業] AI人工智慧 - a.txt
- May 02 Wed 2007 14:15
[課業] AI人工智慧 程式碼
- Apr 26 Thu 2007 16:31
[課業] AI - 注音陣列 - C
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
main ()
{
FILE *fp; //指標 變數名
int i,j,newline;
struct Line{int Lnumx,Lnumy,stx,sty,enx,eny;//線段名稱 <x,y>
char attribute;//存明筆或暗筆 V H
};
//第X劃的第Y線段 設一個Line結構 來存兩個點的值
struct Word{
char s[5];//存注音符號
int count;//存最多可以幾條線
struct Line Lines[10];//用法:結構名+變數名[個數]
}; //設Char的結構來存注音符號、線的數量以及引進Line的格式(兩個點)
//來構成Char
struct Word All[37];//宣告37個
fp=fopen("D:/94413016/20070329/a.txt","r");//開檔
if(fp==NULL){//檢查開檔有沒有成功
printf("open file error\n");
}
/*讀檔*/
for (i=0;i<37;i++) //因為已知txt檔的內容所以才可以這樣寫
{
fscanf(fp,"%s %d",All[i].s,&All[i].count);//將 count 讀入(位置)
for(j=0;j<All[i].count;j++)
{
fscanf(fp,"%d%d%d%d",&All[i].Lines[j].stx,&All[i].Lines[j].sty,
&All[i].Lines[j].enx,&All[i].Lines[j].eny);//印出線的兩個點
All[i].Lines[j].attribute='V';//直接判斷所有輸入的線段為明筆
}
}
fclose(fp);
/*判斷*/
for(i=0;i<37;i++)
{
All[i].Lines[0].Lnumx=1;//預設第一劃等於1
All[i].Lines[0].Lnumy=1;//預設第一線段等於1
for(j=1;j<All[i].count;j++)
{//後測的話J不能等於零(不能為第一劃)
if ((j!=0)
&&(All[i].Lines[j].stx==All[i].Lines[j-1].enx)
&&(All[i].Lines[j].sty==All[i].Lines[j-1].eny))
{
All[i].Lines[j].Lnumx=All[i].Lines[j-1].Lnumx;
All[i].Lines[j].Lnumy=All[i].Lines[j-1].Lnumy+1;//第X筆劃的的第Y+1線段
}else{
All[i].Lines[j].Lnumx=All[i].Lines[j-1].Lnumx+1;
All[i].Lines[j].Lnumy=1;//第X+1筆劃的第1條線段
}
}
}
for(i=0;i<37;i++)//判斷明筆暗筆‧列出暗筆
{
for(j=1;j<All[i].count;j++)
{
if (All[i].Lines[j].Lnumx=All[i].Lines[j-1].Lnumx+1)//如果是新筆劃就插入暗筆
{
for (newline=All[i].count-1;newline>=j;newline--)//newline從後面判斷回前面
{//將J的東西搬進J+1裡面
All[i].Lines[j+1].stx=All[i].Lines[j].stx;
All[i].Lines[j+1].sty=All[i].Lines[j].sty;
All[i].Lines[j+1].enx=All[i].Lines[j].enx;
All[i].Lines[j+1].eny=All[i].Lines[j].eny;
All[i].Lines[j+1].Lnumx=All[i].Lines[j].Lnumx;
}
All[i].count++;
}
else
{
All[i].Lines[j].attribute='H';
All[i].Lines[j].Lnumx=All[i].Lines[j-1].Lnumx+1;
All[i].Lines[j].Lnumy=1;
}
}
}
/*印出*/
for(i=0;i<37;i++)
{
printf("符號:%s\t 線數:%d \n",All[i].s,All[i].count);//印注音符號跟線段數
for(j=0;j<All[i].count;j++)
{
printf("(%d,%d)│%c│(%d,%d)\t(%d,%d)\n",
All[i].Lines[j].Lnumx,
All[i].Lines[j].Lnumy,
All[i].Lines[j].attribute,
All[i].Lines[j].stx,
All[i].Lines[j].sty,
All[i].Lines[j].enx,
All[i].Lines[j].eny);
}
printf("-------------------------------\n");
}
system("pause");
}
- Apr 26 Thu 2007 16:30
[課業] AI - 注音指標 - C
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct Line{int Lnumx,Lnumy,stx,sty,enx,eny,attribute;
struct Line *ptr,*next,*temp;
};
struct Word{
char s[5];
int count;
struct Line *ptr;
};
struct Word All[37];
FILE *fp;
main ()
{struct Line *last=NULL,*now;
int stx,sty,enx,eny;
int i,j;
fp=fopen("D:/94413016/20070329/a.txt","r");
for (i=0;i<37;i++) //因為已知txt檔的內容所以才可以這樣寫
{
fscanf(fp,"%s %d",All[i].s,&All[i].count);//將 count 讀入(位置)
All[i].ptr=NULL;
for(j=0;j<All[i].count;j++)
{
fscanf(fp,"%d%d%d%d",&stx,&sty,&enx,&eny);//印出線的兩個點
if(All[i].ptr==NULL)
{
All[i].ptr=(struct Line *)malloc(sizeof(struct Line));
last=All[i].ptr;
last->stx=stx;
last->sty=sty;
last->enx=enx;
last->eny=eny;
last->attribute=1;
last->ptr=NULL;
}else{
last->ptr=(struct Line *)malloc(sizeof(struct Line));
last=last->ptr;
last->stx=stx;
last->sty=sty;
last->enx=enx;
last->eny=eny;
last->attribute=0;
last->ptr=NULL;
}
now=now->ptr;
}
}
for(i=0;i<37;i++)
{
now=All[i].ptr;
while (now=NULL)
{
if(now->ptr!=NULL)
{
next=now->ptr;
if((now->ex!=next->sx)||(now->ey!=next->sy))
temp=(struct Line *)malloc(sizeof(struct Line));
temp->sx=now->ex;
temp->sy=now->ey;
temp->ex=now->sx;
temp->ey=now->sy;
temp->attribute=0;
temp->ptr=NULL;
temp->ptr=now->ptr;
now->p=temp;
}
now=now->ptr;
}
}
for(i=0;i<37;i++)
{
now=All[i].ptr;
printf("--------------------------\n");
printf("符號:%s\t筆劃:%d\n",All[i].s,All[i].count);
while (now!=NULL){
printf("(%d,%d)\t(%d,%d)\n",now->stx,now->sty,now->enx,now->eny);
now=now->ptr;
}
}
system("pause");
}
- Apr 26 Thu 2007 16:29
[課業] AI - 漢諾塔 - C
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int count=0;
static void H(int n,char A,char B,char C)
{
if (n == 1)
{
printf("從 Disk %d 盤 , 從 %c 移動到 → %c\n",n,A,C);
count++;
}
else
{
H(n - 1, A, C, B);
printf("從 Disk %d 盤 , 從 %c 移動到 → %c\n",n,A,C);
H(n-1,B,A,C);
count++;
}
}
main()
{
int n;
char A='A',B='B',C='C';
printf("請輸入一個數 n : ");
scanf("%d",&n);
H(n,A,B,C);
printf(" N = %d ,共搬移 %d 次",n,count);
system("pause");
}
- Apr 21 Sat 2007 01:31
[課業] System Program Q&A
Assume that you have available to you a 360-type computer and the following available input decks:
Deck A : A Basic Assembly Language (BAL) assembler written in binary code (machine language)
Deck B : A FORTRAN to BAL translator, written in BAL
Deck C : A FORTRAN program that will read data cards and print the square roots of the data
Deck D : A data deck for the square root program of deck C
In order to compute the square roots you will have to make four computer runs. The runs are described schematically below. Each run involves (reading from left to right ) an input deck that will be operated on by a program to produce an output deck. Of course, the output deck produced by one run may be used either the input deck or the program of a subsequent run.
In the figure below identify the unlabelled decks with the letters A,B,C,D,E,F,G.
- Apr 20 Fri 2007 23:24
[課業] 憲法與人權
- Apr 12 Thu 2007 16:34
[課業] AI人工智慧 0412(指標)
- Mar 29 Thu 2007 16:34
[課業] AI人工智慧
1. 寫一程式,將37個標準注音符號字形讀入,並做到以下功能:
- Mar 26 Mon 2007 20:31
[課業] 資結期中考時間
範圍:一到三章
加油!!!
- Mar 22 Thu 2007 16:23
[課業] 人工智慧上課內容
- Mar 15 Thu 2007 16:38
[課業] 人工智慧導論上課內容
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
int a[20];
char b[10];
int c[26];
int i;
char *p,*q;
for(i=0;i<20;i++)
printf("a[%d]的位址: %d\t\t\t",i,&a[i]);
printf("\n");
for(i=0;i<10;i++)
printf("b[%d]的位址: %d\t\t\t",i,&b[i]);
printf("\n");
for(i=0;i<26;i++)
{
c[i]='A'+i;
printf("c[%d]的字母: %c\t",i,c[i]);
}
printf("\n");
p= q= (char *)malloc(26);
for(i=0;i<26;i++)
{
*p='A'+i;
printf("P的初值: %d \t P的位址 %d \t %c \n",p,&p,*p);
p++;
}free(q);
system("pause");
}
- Mar 13 Tue 2007 23:02
[課業] 健康管理報告