2017年12月10日

老鼠走迷宮

#include 
#include 
#define N 100

typedef struct{
  int row,col,dir;
}locate;

typedef struct{
  int horiz,vert;
}offsets;

int Top=-1;                                   /* 初始堆疊頂端 */
locate Stack[N];

offsets move[4]={
  [0]={ .horiz=0,   .vert=-1},    //N
  [1]={ .horiz=1,   .vert=0},     //E
  [2]={ .horiz=0,   .vert=1},     //S
  [3]={ .horiz=-1,  .vert=0}      //W
};

void Push(locate);
locate Pop();
void PrintStack();

int main()
{
    int mrows,mcols,exitrow,exitcol,i,j,row,col,dir=0;
    locate position;

    scanf("%d %d",&mrows,&mcols);           /* Input maze size m*n */
    scanf("%d %d",&exitrow,&exitcol);       /* Input exitrow exitcol */
    int maze[mrows+2][mcols+2];
    int mark[mrows+2][mcols+2];             /* Record Visited position in mark array */

    for(i=0;i<mrows+2;i++)                  /* Initial maze and mark array */
    {
      for(j=0;j<mcols+2;j++)
        {
          mark[i][j]=0;                                 /* Initial mark array to 0 */
          if(i==0 || i==mrows+1 || j==0 || j==mcols+1)  /* if row=0 or row=last row col=0 or col=last col set maze[i][j]=1 be wall */
            maze[i][j]=1;
          else
            scanf("%d",&maze[i][j]);                    /* else input maze data*/
        }
    }

    printf("\n===== 顯示迷宮 =====\n");
    for(i=0;i<mrows+2;i++)
    {
      for(j=0;j<mcols+2;j++)
      {
        if(maze[i][j]==1)
          printf("█");
        else
          printf(" ");
      }
      printf("\n");
    }
    //printf("\n");
    int entr_ROW=1,entr_COL=1;                 /* Set maze entraence(1,1) */
    int next_ROW,next_COL;                     /* next position */

    Top=0;                                     /* push entrance to Stack */
    Stack[0].row=entr_ROW;
    Stack[0].col=entr_COL;
    Stack[0].dir=dir;
    mark[entr_ROW][entr_COL]=1;
    //PrintStack();

    while(Top > -1)
    {
      position=Pop();                          /* pop position from Stack */
      row=position.row;
      col=position.col;
      dir=position.dir;
      //printf("%d %d %d\n",row,col,dir);

      while(dir<4)
      {
        next_ROW=row+move[dir].vert;
        next_COL=col+move[dir].horiz;
        //printf("%d %d %d",next_ROW,next_COL,dir);//break;

        if(next_ROW==exitrow && next_COL==exitcol)
        {
            //mark[next_ROW][next_COL]=1;
            position.row=row;
            position.col=col;
            position.dir=dir;
            Push(position);

            printf("\n===== 顯示迷宮路徑 =====\n");

            for(i=Top;i>=0;i--)
            {
              maze[Stack[i].row][Stack[i].col]=3;
              //printf("%d %d %d\n",Stack[i].row,Stack[i].col,Stack[i].dir);
            }


            for(i=0;i<mrows+2;i++)
            {
              for(j=0;j<mcols+2;j++)
              {
                if(maze[i][j]==0)
                  printf(" ");
                else if(maze[i][j]==1)
                  printf("█");
                else
                  printf("○");
              }
              printf("\n");
            }

            return 0;
        }
        else if(maze[next_ROW][next_COL]==0 && mark[next_ROW][next_COL]==0)
        {
            mark[next_ROW][next_COL]=1;

            position.row=row;
            position.col=col;
            position.dir=dir;
            Push(position);     /* Save the current position */

            row=next_ROW;       /* Specify the next position */
            col=next_COL;
            dir=0;              /* Zero the direction */
        }
        else
            dir++;
      }

    }
   printf("迷宮沒有出口!\n");

   return 0;
}

void Push(locate item)
{
  if(Top==(N-1))
  {
    printf("= Stack full ! =\n");
  }
  else
  {
    //Top=Top+1;
    Stack[++Top]=item;
  }
}

locate Pop()
{
  if(Top==-1)
  {
    printf("= Stack empty ! =\n");
  }
  else
  {
    return Stack[Top--];
  }
}

void PrintStack()
{
  int i;
  if(Top==-1)
  {
    printf("堆疊是空的!\n");
  }
  else
  {
    printf("= Stack contain : =\n");
    for(i=Top;i>=0;i--)
      printf("%d %d %d\n",Stack[i].row,Stack[i].col,Stack[i].dir);
    printf("\n");
  }
}

2017年10月17日

配合排程使用 forfiles 刪除指定檔案

刪除指定的檔案
forfiles /p c:\02FirefoxPortable /s /m *.dll /c "cmd /c erase @path"
forfiles /p c:\02FirefoxPortable /s /m *.chk /c "cmd /c erase @path"
配合排程

2017年9月6日

C_MM29- 最大質數問題

問題描述:試撰寫一個程式,可輸入一個整數,並找出小於此數的最大質數。
輸入說明輸入一個正整數。
輸出說明:輸出最大質數。

#include <stdio.h>  
#include <stdlib.h>  
  
int main()  
{  
    int x,i,j;  
    int isp=0;  
  
    scanf("%d",&x);  
  
    for(i=x-1;i>0;i--)  
    {  
      for(j=2;j<i;j++)  
      {  
        isp=1;  
        if(i%j==0)  
          {  
            isp=0;  
            break;  
          }  
      }  
  
      if(isp==1)  
      {  
        printf("%d\n",i);  
        break;  
      }  
    }  
     return 0;  
} 

C_MM20-十進位轉十六進位

題目描述:
十進位轉十六進位
輸入說明:
輸入一個十進位的整數
輸出說明:
把輸入的數轉為十六進位輸出
#include <stdio.h>  
#include <stdlib.h>  
  
int main()  
{  
    int num,rem,i=0;  
    int ans[99];  
    char a16[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};  
    scanf("%d",&num);  
  
    while(num>0)  
    {  
      rem=num%16;  
      num=num/16;  
  
      ans[i]=rem;  
      i++;  
    }  
  
    while(i>0)  
    {  
      i--;  
      printf("%c",a16[ans[i]]);  
    }  
    printf("\n");  
    return 0;  
} 

C_MM09-計算 i 次方的值

問題描述:
請撰寫一個程式,計算2的 i次方的值。(提示:利用位移運算元)
輸入說明:
輸入一個正整數,i的值小於31。
輸出說明:
輸出 的i次方的值。
若 i > 31 輸出 "Value of more than 31"


#include <stdio.h>  
#include <stdlib.h>  
  
int main()  
{  
    int i,a,sum=1;  
    scanf("%d",&a);  
    if(a<31)  
        {  
            for(i=0;i<a;i++)  
            {  
                sum=sum*2;  
            }  
            printf("%d\n",sum);  
        }  
    else  
        {  
            printf("Value of more than 31\n");  
        }  
  
    return 0;  
}  

C_MM03-兩數總和

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,sum;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
       sum=a+b;
       printf("%d\n",sum);
    }

    return 0;
}

2017年9月5日

質數判別

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n;
    int i,isp;

    scanf("%d",&n);
    for(i=3;i<n;i++)
    {
      isp=1;
      if(n%i==0)
      {
        isp=0;
        break;
      }
    }
    if(isp==1)
      printf("YES\n");
    else
      printf("NO\n");

    return 0;
}

C_MM072-心得報數

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,N,k,num=0;
    int bob=0,count=0,i,j=0;
    scanf("%d",&n);

    while(num<n)
    {
      scanf("%d",&N);
      scanf("%d",&k);
      int all[N];
      int out[N];

      for(i=0;i<N;i++)
      {
        all[i]=i+1;
        out[i]=0;
      }

      while(bob<N-1)
      {
        if(out[j%N]==0)
          count++;
        if(count==k)
        {
          out[j%N]=1;
          count=0;
          bob++;
        }
        j++;
      }

      while(out[j%N]!=0)//找出下一個未爆0
        j++;
      printf("%d\n",all[j%N]);

      j=0;count=0;bob=0;
      num++;
    }


    return 0;
}

2017年4月7日

使用Git and 建立虛擬開發環境

官方網站:
https://git-scm.com/

15分鐘學會 Git
https://try.github.io/levels/1/challenges/1

註冊 Github 帳號
https://github.com/
https://github.com/kdchang

建立虛擬開發環境

http://yannylue.pixnet.net/blog/post/63377682

2017年4月2日

建立開發環境

Anaconda

Cmder
官網:http://cmder.net
延伸閱讀:介紹好用工具:Cmder ( 具有 Linux 溫度的 Windows 命令提示字元工具 )

git
官網:https://git-scm.com 
延伸閱讀:15分鐘學會Git  連猴子都能懂的Git入門指南

 
 Cmder 指令
查看 phthoy 版本:python -V
查看 git 版本:git --version
建立虛擬環境:conda create -n 虛擬環境名稱 python=3.5 anaconda

刪除虛擬開發環境
conda remove -n 虛擬環境名稱 --all
列出所有虛擬環境
conda info -e

啟動虛擬開發環境
activate 虛擬環境名稱

參考來源:
http://yuan.logdown.com/posts/1660420-unit-two-a-development-environment-built