2010/10/28

[c++]魔方陣(奇數階)

#include <iostream> 
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
    int n;
    cout << "請輸入方陣階數:";
    cin >> n;
    int A[n][n];

    int r = 0;
    int c = (n-1)/2;
    int v = 1;

    for(int i = 0; i < n; i++)
    {
        for(int j =0; j<n; j++)
        {
            A[i][j] = -1;
        }
    }

    while(v<=(n*n))
    {
        A[r][c] = v;
        v++;
        r--;
        c++;

        if((r < 0)&&(c <= n-1))
        {
            r = n-1;
        }
        else if ((r>=0) && (c > n-1))
        {
            c = 0;
        }
        else if((r < 0)&&(c > (n-1)))
        {
            r = r+2;
            c--;
        }
        else if(A[r][c]!= -1)
        {
            r = r+2;
            c--;
        }
    }

    for(int i=0; i<n; i++) 
    {
        for(int j=0; j<n; j++) 
        {
            cout << A[i][j] << "\t";
        }
        cout << endl;
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

2010/09/25

[C++]大小寫轉換

[C++]測試字元

(下列函數需引入標頭檔cctype.h)

下列函式判斷結果若為真,傳回非 0 值;若否,則傳回 0


測 試 字 元 函 數
功    能
 isupper()
    判斷()內的字元是否為大寫英文字母(A-Z)
 islower()
    判斷()內的字元是否為小寫英文字母(A-Z)
 isalpha()
    判斷()內的字元是否為英文字母(不分大小寫
 isdigit()
    判斷()內的字元是否為十進位數字(0-9)
 isdxigit()
    判斷()內的字元是否為十六進位數字(0-9,a-f,A-F)
 isalnum()
    判斷()內的字元是否為英文字母或數字(a-z,A-Z,0-9)
 isspace()
    判斷()內的字元是否為空白,\n,\r,\f,\t,\v
 iscntrl()
    判斷()內的字元是否為控制字元
 isprint()
    判斷()內的字元是否為可列印的字元
 ispunct()
    判斷()內的字元是否為標點符號 

2010/07/04

Ubuntu 10.04再起

這算是暑期第一篇的網誌吧
話說自從期末考結束放假
這好像是我慵懶的第二天
切入正題