• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            f(sixleaves) = sixleaves

            重劍無鋒 大巧不工

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              95 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks

            #

            題目意思簡單,模型就是排序,查找是否有該數字,有則輸出位置,沒有輸出提示。
            具體用到了C++ STL的兩個函數模板一個是sort、一個是lower_bound,lower_bound(begin, end, v);
            lower_bound與strchr類似,但它使用的是迭代器begin與end返回的是大于等于v的最小數所在的迭代器,
            使用該模板函數需要注意的問題是,必須是針對已經排序好得數字,具體代碼如下。
             1 #include <cstdio>
             2 #include <algorithm>
             3 
             4 using namespace std;
             5 const int maxn = 10000;
             6 
             7 
             8 int main() {
             9     
            10     int n, q, x, a[maxn], kase = 0;
            11     while (scanf("%d%d", &n, &q) == 2 && n) {
            12         
            13         for (int i = 0; i < n; i++) scanf("%d", &a[i]);
            14         sort(a, a+n);
            15         printf("CASE# %d:\n", ++kase);
            16         while (q--) {
            17             
            18             scanf("%d", &x);
            19             int p = lower_bound(a, a+n, x) - a;
            20             if (a[p] == x) printf("%d found at %d\n", x, p + 1);
            21             else printf("%d not found\n",x);
            22             
            23         }
            24     }
            25     return 0;
            26 }
            posted @ 2015-02-12 10:43 swp 閱讀(127) | 評論 (0)編輯 收藏

            /Files/sixleaves/253.pdf 
            題目在上面,可以自己下載,這道一開始沒什么思路,后來仔細想想,突然有了點靈感,但是還是找不到比較簡單的辦法
            程序還有優化的地步,用到的全局變量有點多。
            我的思路是:每個數字都有一個位于Top也就是最頂得時候,只要在這時候,豎直旋轉4次,分別判斷就可以知道是否存在相同的cube了。
            程序主體框架挺清晰的,但是有一點就是下標沒處理好,有興趣的,可以自己統一一下。
            by sixleaves
             1 #include <stdio.h>
             2 
             3 //  枚舉各個數字位于"上"的一種可能情況
             4 //  該情況下,各個數字所處的位置
             5 int cubeTop[7][7] = {
             6     {0,0,0,0,0,0,0},
             7     {0,1,2,3,4,5,6},
             8     {0,2,6,3,4,1,5},
             9     {0,3,2,6,1,5,4},
            10     {0,4,2,1,6,5,3},
            11     {0,5,1,3,4,6,2},
            12     {0,6,5,3,4,2,1}
            13 };
            14 
            15 
            16 int lastCube[7] = {0};
            17 int curCube[7] = {0};
            18 
            19 int isFind;
            20 
            21 // [0,6)  [6,12)--為另外一個cube
            22 char s[15] = {0};
            23 void turn();
            24 void update();
            25 int isSameCube();
            26 int main() {
            27     
            28     while (scanf("%s",s) != EOF) {
            29     
            30         // 枚舉top面數字
            31         isFind = 0;
            32         for (int i = 1; i <=6; i++) {
            33             
            34             //  初始化當前篩子
            35             for (int k = 1; k <= 6; k++) {
            36                 lastCube[k] = curCube[k] = cubeTop[i][k];
            37             }
            38             
            39             // 豎直轉動4次篩子
            40             for (int j = 0; j < 4; j++) {
            41                 
            42                 turn();
            43                 
            44                 if (isSameCube()) {
            45                     isFind = 1;
            46                     break;
            47                 }
            48                 
            49             }
            50             
            51             if (isFind) {
            52                 break;
            53             }
            54         }
            55         
            56         printf( isFind == 1? "TRUE\n" : "FALSE\n");
            57         
            58     }
            59     return 0;
            60 }
            61 
            62 int isSameCube() {
            63     
            64     //分別比較對應6個面
            65     for (int i = 0; i < 6; i++) {
            66         if (s[curCube[i + 1] - 1] != s[i + 6])
            67             return 0;
            68     }
            69     return 1;
            70 }
            71 
            72 void turn() {
            73     
            74     curCube[2] = lastCube[3];
            75     curCube[4] = lastCube[2];
            76     curCube[5] = lastCube[4];
            77     curCube[3] = lastCube[5];
            78     //  更新lastCube
            79     update();
            80 }
            81 
            82 void update() {
            83     
            84     lastCube[2] = curCube[2];
            85     lastCube[4] = curCube[4];
            86     lastCube[5] = curCube[5];
            87     lastCube[3] = curCube[3];
            88     
            89 }
            posted @ 2015-02-08 01:42 swp 閱讀(194) | 評論 (0)編輯 收藏

            這道題目略坑,如果用模擬來做的話,其實很簡單,一開始想的是模擬之后覺得集合更簡答,但是忽略了一點是,用集合來做的話,集合是無序的,但是題目中得輸入順序是有序的。而且用模擬的時間復雜度為O(n^2).

             1 #include <stdio.h>
             2 #include <string.h>
             3 #define MAXN 1024
             4 
             5 int left, chance;
             6 int win, lose;
             7 void guess(char ch);
             8 
             9 char p[MAXN] = {0}, g[MAXN] = {0};
            10 int main() {
            11     
            12     int r = 0;
            13     
            14     while (scanf("%d%s%s",&r, p, g) == 3 && r != -1) {
            15         
            16         printf("Round %d\n", r);
            17         win = lose = 0;
            18         left = strlen(p);
            19         chance = 7;
            20         for (int i = 0; g[i]; i++) {
            21             
            22             guess(g[i]);
            23             
            24             if (win || lose) break;
            25             
            26         }
            27         
            28         if (win) printf("You win.\n");
            29         else if(lose) printf("You lose.\n");
            30         else printf("You chickened out.\n");
            31         
            32     }
            33     return 0;
            34 }
            35 
            36 
            37 void guess(char ch) {
            38     
            39     int finded = 0;
            40     for (int i = 0; p[i]; i++) {
            41         
            42         if (ch == p[i]) {
            43             p[i] = ' ';
            44             left--;
            45             finded = 1;
            46             
            47         }
            48         
            49     }
            50     
            51     if (!finded) --chance;
            52     if (!chance) lose = 1;
            53     if (!left) win = 1;
            54     
            55 }

            by sixleaves
            posted @ 2015-02-07 13:29 swp 閱讀(133) | 評論 (0)編輯 收藏

            被坑了,2小時的題目,==。題目難點主要在處理空格和輸出格式上。對于這種模擬題,我是先把框架寫好,在補充。
            寫得比較長,沒有進行重構,就這樣吧。getchar()等I/O雖然會讀取回車,但是要按下回車,產生中斷,在會結束輸
            告訴這些I/O函數來讀取==。總之這題目,沒什么特別的思想,完全是模擬題,能寫:?的語句,盡量寫,簡化代碼
            還有代碼寧愿嚴密啰嗦,也不要有Bug

            #include <stdio.h>

            #include <string.h>

            typedef struct {

                int r;

                int c;

            } Point;


            int main() {

                

                const int maxn = 5;

                char puzzle[maxn][maxn] = {0};

                int kase = 0;

                int first = 1;

                for (;;) {

                    

                    //  1.先讀取一個字符,看是不是Z,不是Z得看看是不是空字符

                    char ch;

                    ch = getchar();

                    if (ch == 'Z') break;

                    else {

                        puzzle[0][0] = ch;

                        first == 1? first = 0: printf("\n");

                    }

                    

                    Point empty;

                    if (ch == ' ') { empty.r = 0, empty.c = 0; }

                    

                    //  2.讀取Puzzle初始化布局

                    for (int i = 1; i < 25; ) {

                        ch = getchar();

                        if (ch == ' ') {

                            puzzle[ empty.r = i / 5 ][ empty.c = i % 5 ] = ch;

                            i++;

                        }

                        if (ch != ' ' && ch != '\n' && ch != '\t' && ch != '\r') {

                            puzzle[ i/5 ][ i%5 ] = ch;

                            i++;

                        }

                    }

                    

                    //  3.執行指令

                    int configuration = 1;

                    while ((ch = getchar()) != '0') {

                        

                        if (ch == '\n' || ch == ' ' || !configuration) continue;

                        int row = empty.r, col = empty.c;

                        if (configuration) {

                            switch (ch) {

                                    

                                case 'A':

                                    if (row - 1 >= 0) {

                                        puzzle[row][col] = puzzle[row - 1][col];

                                        puzzle[row - 1][col] = ' ';

                                        empty.r = row - 1;

                                        empty.c = col;

                                    }else {

                                        configuration = 0;

                                    }

                                    break;

                                case 'B':

                                    if (row + 1 < maxn) {

                                        puzzle[row][col] = puzzle[row + 1][col];

                                        puzzle[row + 1][col] = ' ';

                                        empty.r = row + 1;

                                        empty.c = col;

                                    }else {

                                        configuration = 0;

                                    }

                                    break;

                                case 'R':

                                    if (col + 1 < maxn) {

                                        puzzle[row][col] = puzzle[row][col + 1];

                                        puzzle[row][col + 1] = ' ';

                                        empty.r = row;

                                        empty.c = col + 1;

                                    }else {

                                        configuration = 0;

                                    }

                                    break;

                                case 'L':

                                    if (col - 1 >= 0) {

                                        puzzle[row][col] = puzzle[row][col - 1];

                                        puzzle[row][col - 1] = ' ';

                                        empty.r = row;

                                        empty.c = col - 1;

                                    }else {

                                        configuration = 0;

                                    }

                                    break;

                                default:

                                    configuration = 0;

                                    break;

                                    

                            }

                        }

                        

                    }

                    //  4.吃掉回車

                    ch = getchar();

                    

                    //  5.輸出

                    if (!configuration) {

                        printf("Puzzle #%d:\nThis puzzle has no final configuration.\n", ++kase);

                    }else {

                        printf("Puzzle #%d:\n", ++kase);

                        for (int row = 0; row < maxn; row++) {

                            

                            for (int col = 0; col < maxn; col++) {

                                

                                printf(col == maxn - 1 ? "%c" : "%c ", puzzle[row][col]);

                                

                            }

                            printf("\n");

                        }

                    }

                    

                }

                

                return 0;

            }

            posted @ 2015-02-06 10:24 swp 閱讀(364) | 評論 (0)編輯 收藏

            這題,求最小周期。有點坑的是格式說明,Two consecutive output are separated by a blank line.兩種數據輸出之間要有個空白行。
            還有另外一個,len % t == 0是必須得,因為只有是周期倍數的才能求出周期。不然如:abcdabc求出的周期就變成了3.

             1 #include <stdio.h>
             2 #include <string.h>
             3 const int maxn = 1024;
             4 char buf[maxn] = {0};
             5 int isT(char * buf, int len,int t);
             6 int main() {
             7     
             8     int n;
             9     while (~scanf("%d",&n))
            10         while ( n > 0 ) {
            11             
            12             //  輸入
            13             scanf("%s",buf);
            14             int len = strlen(buf);
            15             
            16             //  計算最小周期,從小到大枚舉
            17             for (int t = 1; t <= len; t++) {
            18                 if (len % t == 0)
            19                     if (isT(buf, len, t)) {
            20                         printf("%d\n", t);
            21                         break;
            22                     }
            23             }
            24             
            25             if (--n) printf("\n");
            26         }
            27     
            28     return 0;
            29 }
            30 
            31 int isT(char * buf, int len,int t) {
            32     
            33     for (int i = t; i < len; i++) {
            34         
            35         if (buf[i % t] != buf[i]) {
            36             
            37             return 0;
            38         }
            39     }
            40     
            41     return 1;
            42 }

            by sixleaves
            posted @ 2015-02-05 20:01 swp 閱讀(182) | 評論 (0)編輯 收藏

            1.其實是dp題目。用建表方法避免了重復計算

             1 #include <stdio.h>
             2 const int maxn= 10008;
             3 int count[maxn][10] = {0};
             4 int main() {
             5     
             6     
             7     int n;
             8     char buf[maxn] = {0};
             9     
            10     //計算每一位
            11     for (int i = 1; i<= maxn; i++) {
            12         
            13         sprintf(buf,"%d", i);
            14         for (int j = 0; buf[j]; j++) {
            15             count[i][buf[j]-'0']++;
            16         }
            17         
            18     }
            19     
            20     //建立數據,防止重復計算
            21     for (int i = 2; i <= maxn; i++) {
            22         
            23         for (int j = 0; j < 10; j++) {
            24             
            25             count[i][j] += count[i - 1][j];
            26             
            27         }
            28     }
            29     
            30     scanf("%d", &n);
            31     while (n > 0) {
            32         int e;
            33         scanf("%d", &e);
            34         
            35         for (int i = 0; i < 10; i++) {
            36             printf( i == 9? "%d\n" : "%d ", count[e][i]);
            37         }
            38         
            39         n--;
            40     }
            41 }
            by sixleaves
            posted @ 2015-02-05 19:53 swp 閱讀(515) | 評論 (1)編輯 收藏

             思路,其實還是切分單詞,只不過這里的單詞,變成了數字。代碼如下。

             1 #include <stdio.h>
             2 #include <string.h>
             3 #include <ctype.h>
             4 #define MAXN 100
             5 
             6 char buf[MAXN] = {0};
             7 double t[26] = {0};
             8 int readInt(char * buf, int i, int *num);
             9 int main() {
            10     
            11     int n;
            12     int ch, num;
            13     t['C'-'A'] = 12.01, t['H'-'A'] = 1.008;
            14     t['O' - 'A'] = 16.00, t['N' - 'A'] = 14.01;
            15     scanf("%d", &n);
            16     
            17     while (n > 0) {
            18         
            19         //  1.輸入數據
            20         scanf("%s", buf);
            21         int len = strlen(buf);
            22         double sum = 0.0;
            23         int i = 0;
            24         
            25         //  2.計算
            26         for (;;) {
            27             
            28             for (; buf[i]&&isalpha(buf[i]); i++) {
            29                 sum += t[buf[i] - 'A'];
            30             }
            31             if (i >= len) break;
            32             
            33             //  2.1[i, e)為整數范圍,num為整數值
            34             int e,num;
            35             e = readInt(buf, i, &num);
            36             sum += t[buf[i - 1] - 'A'] * (num - 1);
            37             i = e;
            38         }
            39         
            40         //  3.輸出結果
            41         printf("%.3f\n", sum);
            42         n--;
            43     }
            44     
            45     return 0;
            46 }
            47 
            48 //  如果沒有找到則返回i
            49 int readInt(char * buf, int i, int *num) {
            50     int sum = 0;
            51     int j;
            52     for (j = i; buf[j] && isdigit(buf[j]); j++) {
            53         sum *= 10;
            54         sum += buf[j] - '0';
            55     }
            56     *num = sum;
            57     return j;
            58     
            59 }
            by sixleaves
            posted @ 2015-02-05 19:37 swp 閱讀(485) | 評論 (0)編輯 收藏

             雖然為水題,但是我的算法還是比較一般。思想是切分單詞的思想,確定切分開始條件,結束條件,在[b,e)之間就是所得單詞,因為單詞以X作為間隔,為了保證算法正確性,需要在末尾添加X。算法如下
             1 #include <stdio.h>
             2 #include <string.h>
             3 #define MAXN 86
             4 int main() {
             5     
             6     int n;
             7     char buf[MAXN] = {0};
             8     scanf("%d", &n);
             9     typedef enum {
            10         WordIn,
            11         WordOut,
            12     } Word;
            13     while ( n--> 0) {
            14         
            15         scanf("%s", buf);
            16         int sum = 0, b = 0, e = 0, len = strlen(buf);
            17         buf[len++] = 'X', buf[len] = '\0';
            18         Word word = WordOut;
            19         
            20         //  遍歷字符串
            21         for (int i = 0; buf[i]; i++) {
            22             
            23             //  記錄單詞開頭
            24             if (buf[i] == 'O') {
            25                 
            26                 b = word == WordOut? ( word = WordIn, i) : b;
            27                 
            28             }else {
            29                 
            30                 //  記錄單詞結尾,并作統計
            31                 if (word == WordIn) {
            32                     word = WordOut;
            33                     e = i;
            34                     int max = e - b;
            35                     sum += max*(max + 1) / 2;
            36                 }
            37                 
            38             }
            39         }
            40         printf("%d\n", sum);
            41     }
            42     return 0;
            43 }
            by sixleaves
            posted @ 2015-02-05 09:09 swp 閱讀(1371) | 評論 (0)編輯 收藏

            這篇主要總結下cocos2dx中常用到的3大宏定義(數學類宏定義、數據結構相關宏定義、對象相關宏定義),由于在win下的vs編譯太慢,所以這些測試代碼都是在mac下編譯的,有如下
            之所以分為三大類是為了方便記憶、歸納。分類不在于分細、而在于簡約、容易記憶。
            1.數學相關的宏
            CCRANDOM_MINUS1_1()、CCRANDOM_0_1()、CC_DEGREES_TO_RADIANS、CC_RADIANS_TO_DEGREES()

            1 log("CCRANDOM_MINUS1_1=%f", CCRANDOM_MINUS1_1());
            2 log("CCRANDOM_0_1=%f", CCRANDOM_0_1());
            3 log("CC_DEGREES_TO_RADIANS(30)=%f", CC_DEGREES_TO_RADIANS());
            4 log("CC_RADIANS_TO_DEGREES(180)=%f",CC_RADIANS_TO_DEGREES());
            5 int x = 10;
            6 int y = 20;
            7 CC_SWAP(x, y, int);
            8 log("交換后x=%d,y=%d",x,y);
            輸出:
            1 cocos2d: CCRANDOM_MINUS1_1()=-0.999984
            2 cocos2d: CCRANDOM_0_1()=0.131538
            3 cocos2d: CC_DEGREES_TO_RADIANS()=0.523599
            4 cocos2d: CC_RADIANS_TO_DEGREES()=20626.480469
            5 cocos2d: x=20,y=10
            #1.2斷言宏
            把這個歸位數學類,是因為我認為,斷言本身就是屬于數學的一種抽象名詞
            ASSERT(cone, msg);
            第一個參數是條件,為false則提示msg消息。
            1     Point *point = NULL;
            2 //    CCAssert(point != NULL,"something wrong");
            3     CCASSERT(point != NULL, "somthing wrong");
            輸出:
            1 cocos2d: Assert failed: somthing wrong
            2 Assertion failed: (point != __null), function init, file /Users/mac/Desktop/gameDevelopment/1410/testMacro/Classes/HelloWorldScene.cpp, line 39.


            2.與特定數據結構相關的宏(主要用來遍歷、如同迭代器)
            CCARRAY_FOREACH、CCDICT_FOREACH
            CCARRAY_FOREACH
            1     __Array * arrayMe = __Array::create();
            2     arrayMe->addObject(__Integer::create(1));
            3     arrayMe->addObject(__Integer::create(2));
            4     arrayMe->addObject(__Integer::create(3));
            5     Ref * ref = NULL;
            6     CCARRAY_FOREACH(arrayMe, ref) {
            7         Integer *pInt = (Integer *)ref;
            8         log("CCARRAY_FOREACH:%d", pInt->getValue());
            9     }

            輸出:

            cocos2d: CCARRAY_FOREACH:1

            cocos2d: CCARRAY_FOREACH:2

            cocos2d: CCARRAY_FOREACH:3

            CCDICT_FOREACH
            1     __Dictionary * dict = __Dictionary::create();
            2     dict->setObject(__Integer::create(1), "one");
            3     dict->setObject(__Integer::create(2), "two");
            4     dict->setObject(__Integer::create(3), "three");
            5     DictElement *el = NULL;
            6     CCDICT_FOREACH(dict, el) {
            7         __Integer *pVlaue = (__Integer*)el->getObject();
            8         log("KEY=%s,CCDICT_FOREACH %d",el->getStrKey(),pVlaue->getValue());
            9     }
            需要注意的是dictionary中得元素都是DictElement類型,其封裝了每個元素的Object和對應的key。
            輸出:

            cocos2d: KEY=one,CCDICT_FOREACH 1

            cocos2d: KEY=two,CCDICT_FOREACH 2

            cocos2d: KEY=three,CCDICT_FOREACH 3



            3.對象相關宏定義
            #3.1對象創建方法宏CREATE_FUNC
            這里直接貼出這個的宏定義,其主要意思
            就是先new、new完后是通過init初始化,而不是構造函數。如果
            init返回false,也就是失敗。則釋放對象返回NULL。否則,把其加入
            自動管理的內存池,然后返回該對象的引用(本質是指針)。
             1 #define CREATE_FUNC(__TYPE__) \
             2 static __TYPE__* create() \
             3 { \
             4     __TYPE__ *pRet = new __TYPE__(); \
             5     if (pRet && pRet->init()) \
             6     { \
             7         pRet->autorelease(); \
             8         return pRet; \
             9     } \
            10     else \
            11     { \
            12         delete pRet; \
            13         pRet = NULL; \
            14         return NULL; \
            15     } \
            16 }
            17 
            #3.2屬性定義宏
            CC_PROPERTY(tpye, varName, funName);
            這個功能其就是用C++得方式,實現了C#中的屬性,通過這個宏定義,
            可以自動生產protected的成員變量,和public的虛setter、getter方法
            具體的setter、getter實現需要,自己實現。如下
            //Monster.h
            #ifndef __Monster_H__
            #define __Monster_H__
            #include "cocos2d.h"
            USING_NS_CC;
            class Monster:public Sprite {
                CC_PROPERTY(int, _monsterHp, MonsterHp);
            public:
                virtual bool init();
                CREATE_FUNC(Monster);
            };
            #endif
            //Monster.cpp
            //
            //  Monster.cpp
            //  testMacro
            //
            //  Created by sixleaves on 14-10-9.
            //
            //

            #include "Monster.h"


            void Monster::setMonsterHp(int var) {
                _monsterHp = var;
            }

            int Monster::getMonsterHp() {
                return _monsterHp;
            }

            bool Monster::init() {
                return true;
            }
            //HelloWorldScene.cpp
             auto monster = Monster::create();
             monster->setMonsterHp(100);
             log("monster HP = %d", monster->getMonsterHp());
            輸出: cocos2d: monster HP = 100
            提示:還有CC_RROPERTY_XXXX系列的其他宏定義,這里只介紹這個,因為比較常使用,其他自己了解。

            2014.10.09 by sixleaves
            posted @ 2014-10-09 14:29 swp 閱讀(2946) | 評論 (0)編輯 收藏

            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); cocos2dx封裝了一些常用的數據結構,我們分為兩個部分介紹。一部分是對基本數據類型,int、float、double、bool的裝箱。一部分是比較復雜的復合數據結構__String、__Array、__Dictionary、Size、Rect、Point、這些數據結構大多數是用C++方式重寫了OC語言中Foundation框架的接口。所以有OC底子的可以調過,大概瀏覽即可。
            第一部分:
                  int對應的裝箱是Integer,在cocos2dx中創建這種整數對象是用create方法,auto pInt = Integer::create(30);
                  int       ---------auto pInt      = __Integer::create(2);
                  double ---------auto pDouble =  __Double::create(1.0);
                  float    ---------auto pFloat    =  __Float::create(2.0);
            第二部分:
                  復合數據結構
                  __String
                  auto pStr = String::create("cocos2dx");
                  auto pStr2 = String::createWithFormat("I love %s", pStr->getCString());
              bool isEqualEach = pStr->isEqual(pStr2);
              log("%s",isEqualEach == true?"Equal":"not Equal");
                 #結果是notEqual
                 __Array
                 Array對象是對C++中數組的封裝。Array中的元素是Ref、可以存不同的數據類型。
                 創建一個空數組,Array::create()
                 增:add系列、addObject 刪:removeXXX系列,代表removeObjectAtIndext() 改:replaceObjectAtIndex()  查:get系列、getIndexOfObject()
                
                 __Dictionary
                 創建字典對象,auto pDict = Dictionary::create()
                 添加鍵值對,pDict->setObject(obj, "key");
                 刪除鍵對應的值, pDict->removeObjectForKey("someKey");
                 查                 ,pDict->ObjectForKey("someKey");
                 auto pDict = Dictionary::create();
                 auto pV1 = String::create("V1");
                 auto pV2 = String::create("V2");
                 pDict->setObject(pV1, "key1");
                 pDict->setObject(pV2, "key2");
                 String *pStr1 = (String*)pDict->ObjectForKey("key1");
                 String *pStr2 = (String*)pDict->ObjectForKey("key2");
                 log("str1 = %s,str2 = %s", pStr1->getCString(), pStr2->getCString());
                #使用ObjectForKey獲得的是Object對象,要強制類型轉換為你確定的那個類型。
                Size、Rect、Point
                Size于Rect的區別是Size只有長寬的屬性,而Rect還有個起始點屬性,他們都是表示一塊矩形區域。
                其中Rect最常使用的是用來判斷某個點在不再這個矩形區域內。其實他們都是對象,不像OC中是結構體。
                 1     //生成兩個點
             2     Point point1 = Point(10,10);
             3     Point point2 = Point(60,60);
             4     Point point3;
             5     //點1與x軸的夾角
             6     log("\n點1(%f,%f)與x軸的夾角為:%f",point1.x,point1.y,point1.getAngle());
             7     //兩個點的夾角
             8     log("\n點1(%f,%f)與點2(%f,%f)的夾角為:%f",point1.x,point1.y,point2.x,point2.y,point1.getAngle(point2));
             9     //兩個點的距離
            10     log("\n點1(%f,%f)與點2(%f,%f)的距離為:%f",
            11     point1.x,point1.y,point2.x,point2.y,point1.getDistance(point2));
            12     //兩個點相加
            13     point3 = point1 + point2;
            14     log("\n(%f,%f)+(%f,%f)=(%f,%f)",point1.x,point1.y,point2.x,point2.y,point3.x,point3.y);
            15     //兩個點相減
            16      point3 = point1-point2;
            17     log("\n(%f,%f)-(%f,%f)=(%f,%f)",point1.x,point1.y,point2.x,point2.y,point3.x,point3.y);
            18     //除法
            19     point3 = point1/2;
            20     log("\n(%f,%f)/2=(%f,%f)",point1.x,point1.y,point3.x,point3.y);
            21     //乘法
            22     point3 = point1*2;
            23     log("\n(%f,%f)+(%f,%f)=(%f,%f)",point1.x,point1.y,point2.x,point2.y,point3.x,point3.y);
            24 
            25     //使用SizeMake創建兩個Size
            26     Size size1 = Size(10, 20);
            27     Size size2 = Size(50, 60);
            28     Size size3;
            29     //兩個Size相加
            30     size3 = size1 + size2;
            31     log("size(%f,%f)+size(%f,%f)=size(%f,%f)",size1.width,size1.height,size2.width,size2.height,size3.width,size3.height);
            32     //兩個Size相減
            33     size3 = size1 - size2;
            34     log("size(%f,%f)-size(%f,%f)=size(%f,%f)",size1.width,size1.height,size2.width,size2.height,size3.width,size3.height);
            35     //Size乘法
            36     size3 = size1*10;
            37     log("size(%f,%f)*10=size(%f,%f)",size1.width,size1.height,size3.width,size3.height);
            38     //Size除法
            39     size3 = size1/10;
            40     log("size(%f,%f)/10=size(%f,%f)",size1.width,size1.height,size3.width,size3.height);
            41 
            42 
            43     //Rect測試
            44     //生成一個坐標為10,20,寬為50,高為30的矩形區域
            45     Rect rect = Rect(10, 20, 50, 30);
            46     //生成兩個點
            47     point1 = Point(15,25);
            48     point2 = Point(100,100);
            49     if (rect.containsPoint(point1)) {
            50         log("rect包含點point1\n");
            51     }else{
            52         log("rect不包含點point1\n");
            53     }
            54     if (rect.containsPoint(point2)) {
            55         log("rect包含點point2\n");
            56     }else{
            57         log("rect不包含點point2\n");
            58     }
            59     //獲取rect矩形區域最左、右、上、下、中間的坐標點
            60     float maxX = rect.getMaxX();
            61     float minX = rect.getMinX();
            62     float maxY = rect.getMaxY();
            63     float minY = rect.getMinY();
            64     float midX = rect.getMidX();
            65     float midY = rect.getMidY();
            66     log("rect的左下角坐標為(%f,%f)\n左上角坐標為(%f,%f)\n右下角坐標為(%f,%f)\n右上角角坐標為(%f,%f)\n中點坐標為(%f,%f)\n"
            67         ,minX,minY,minX,maxY,maxX,minY,maxX,maxY,midX,midY);
            by sixleaves
            posted @ 2014-10-07 23:59 swp 閱讀(3113) | 評論 (0)編輯 收藏

            僅列出標題
            共10頁: First 2 3 4 5 6 7 8 9 10 
            国产国产成人久久精品| 久久本道久久综合伊人| 色狠狠久久AV五月综合| 韩国无遮挡三级久久| 久久久艹| 国产精品久久毛片完整版| 日本高清无卡码一区二区久久| 99精品久久久久久久婷婷| 久久99毛片免费观看不卡| 区久久AAA片69亚洲| 色综合久久天天综合| 亚洲va久久久噜噜噜久久天堂 | 久久人人爽人人爽人人片av高请 | 国产精品久久久久久福利漫画| 久久久久国产成人精品亚洲午夜| 欧美午夜精品久久久久免费视| 久久性生大片免费观看性| 国产91久久精品一区二区| 97精品伊人久久久大香线蕉 | 无码AV中文字幕久久专区| 国产精品热久久毛片| 久久99精品久久久久久动态图 | 久久综合成人网| 亚洲国产成人久久综合一 | 66精品综合久久久久久久| 亚洲精品高清国产一线久久| 亚洲国产香蕉人人爽成AV片久久| 91久久精品国产91性色也| 国内精品伊人久久久久av一坑| 久久人人爽人人爽人人av东京热 | 一本色综合网久久| 2021国产精品久久精品| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久综合给合久久狠狠狠97色69| 久久人人爽人人澡人人高潮AV| 丰满少妇人妻久久久久久4| 久久婷婷综合中文字幕| 狠狠色丁香婷综合久久| 久久国产精品99精品国产987| 久久99国产精品久久| 91精品久久久久久无码|