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 阅读(104) | 评论 (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 阅读(169) | 评论 (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 阅读(110) | 评论 (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 阅读(339) | 评论 (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 阅读(155) | 评论 (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 阅读(494) | 评论 (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 阅读(463) | 评论 (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 阅读(1350) | 评论 (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 阅读(2911) | 评论 (0)编辑 收藏

@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.cppblog.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 阅读(3080) | 评论 (0)编辑 收藏

仅列出标题
共10页: First 2 3 4 5 6 7 8 9 10