﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-厚积薄发，滴水穿石-随笔分类-C</title><link>http://www.cppblog.com/cokecoffe/category/17379.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 10 May 2012 08:48:03 GMT</lastBuildDate><pubDate>Thu, 10 May 2012 08:48:03 GMT</pubDate><ttl>60</ttl><item><title>几个弱智C题</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 05 May 2012 12:00:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/173769.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/173769.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/173769.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;">从网上下了一个C的笔试题，发现附带的答案，不是错的，就是很初级的人写的，发现看了半天，没看懂！于是自己写了一下</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: STSong; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><span style="font-family: 'Trebuchet MS'; "><strong>1.给定一个字符串，输出本字符串中只出现一次并且最靠前的那个字符的位置？</strong></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><span style="font-family: 'Trebuchet MS'; "><strong><span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">比如</span>"abaccddeeef" <span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">则是</span>b<span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">，输出</span>2</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;">int</span> find_char(<span style="color: #b933a1;">const</span> <span style="color: #b933a1;">char</span> *str)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">int</span> pos[<span style="color: #2934d5;">256</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">const</span> <span style="color: #b933a1;">char</span> *p = str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">if</span>((!str)||!(*str))<span style="color: #008212;">//</span><span style="font: 13.0px 'Heiti SC Light'; color: #008212;">空指针或者空串</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">return</span> -<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #33595d;">memset</span>(pos,-<span style="color: #2934d5;">1</span>,<span style="color: #b933a1;">sizeof</span>(pos));</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-variant: normal; font-weight: normal; line-height: normal; min-height: 15px; "><em>//遍历一遍，存下每个字母的位置，如果存过一次，就把位置设置为-2</em></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (*p)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> (pos[*p] == -<span style="color: #2934d5;">1</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos[*p] = p - str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">else</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos[*p] = -<span style="color: #2934d5;">2</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-variant: normal; font-weight: normal; line-height: normal; min-height: 15px; "><em>//遍历存储字母位置的数组，如果存有位置，则返回</em></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;p = str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (*p)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> (pos[*p]&gt;=<span style="color: #2934d5;">0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">return</span> pos[*p];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;"><br /></span></p>
<p style="font-family: Menlo; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">&nbsp; &nbsp;<span style="color: #b933a1;">return</span> -<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">}</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-style: normal; font-variant: normal; line-height: normal; "><strong>&nbsp;</strong></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: STSong; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><strong><span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span>，给定一个整数，问这个整数转成<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span>进制后，里面包含有多少个<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">1</span>？比如：<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">10</span>，二进制表示为，<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">1010</span>则，输出<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span></strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;">int</span> howmany(<span style="color: #b933a1;">int</span> x)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">int</span> count = <span style="color: #2934d5;">0</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (x)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> ((x&amp;<span style="color: #2934d5;">1</span>) == <span style="color: #2934d5;">1</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = x&gt;&gt;<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">return</span> count;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;"><span style="font: 12.0px Times;"><br /></span></p><img src ="http://www.cppblog.com/cokecoffe/aggbug/173769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-05 20:00 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>螺旋队列</title><link>http://www.cppblog.com/cokecoffe/archive/2012/04/15/171483.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sun, 15 Apr 2012 08:44:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/04/15/171483.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/171483.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/04/15/171483.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/171483.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/171483.html</trackback:ping><description><![CDATA[<p>参考：http://blog.csdn.net/yhmhappy2006/article/details/2934435</p>
<p>最近在看一些算法题，看到了螺旋队列。开始自己想了想，但是想到了一半，跟正确思路有些距离，感觉是跟每一圈的最大数有关系的公式。看了正确答案后发现确实如此。整理一下思路：</p>
<p>1.首先要判断给出的坐标（x,y)来计算出坐标所属的圈c。</p>
<p>2.算出当前圈的最大的数max，可以根据这个数来推导给出坐标的值的关系。</p>
<p>3.计算出每个边的基准值(base）与最大值的关系，即每个边上的中间的那个数。</p>
<p>4.根据给出的坐标，判断它是属于（上、下、左、右边）哪个边的。然后推导这个数(value)与基准值和（x,y)坐标的关系。</p>
<p><img title="1334250330_8408.jpg" src="http://www.cppblog.com/images/cppblog_com/cokecoffe/1334250330_8408.jpg" border="0" alt="1334250330 8408" width="600" height="393" /></p>
<p style="color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px; margin: 0px;">下面得出每条边的值，首先考虑上边和下边，这2条边，在基准值的基础上，由x坐标控制增减，因此：</p>
<p style="color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px; margin: 0px;"> </p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;"><span style="vertical-align: super;">topValue=topBase+x=max+y+x</span><span style="vertical-align: super;">（上边，随x赠而赠，因此是加x）</span><span style="vertical-align: super;"> </span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;"><span style="vertical-align: super;">bottomValue=bottomBase-x=max-5y-x</span><span style="vertical-align: super;">（下边，随x赠而减，因此是减x）</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="vertical-align: super; font-family: 'Hiragino Sans GB'; font-size: 13px;">同理，左边和右边，则在基准值的基础上，由y坐标控制增减，因此：</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="vertical-align: super; font-family: 'Hiragino Sans GB'; font-size: 13px;">leftValue=leftBase-y=max+3x-y（左边，随y赠而减，因此是减y）</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="vertical-align: super; font-family: 'Hiragino Sans GB'; font-size: 13px;">rightValue=rightBase+y=max-7x+y（右边，随y赠而赠，因此是加y）</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><br /></span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;">private static Object spiral(int x, int y)</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;">{</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>int c = max(abs(x), abs(y));// 当前坐标所在圈</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>int max = (c * 2 + 1) * (c * 2 + 1);// 当前圈上最大值</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><br /><span style="white-space: pre;"> </span>if (y  -c)</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;">{ // 上边<span style="white-space: pre;"> </span></span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span> return max + (x + y);</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>}</span></span><span style="font-family: Calibri; font-size: 15px;">else if (x  -c)</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;">{// 左边</span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>return max + (3 * x - y);<span style="white-space: pre;"> </span></span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; vertical-align: super;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span> }</span></span><span style="font-family: Calibri; font-size: 15px;"> else if (y == c)</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;">{// 下边</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>return max + (-x - 5 * y);</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>}</span><span style="font-family: Calibri; font-size: 15px;">else</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;">{</span><span style="font-family: Calibri; font-size: 15px;"> // 右边<span style="white-space: pre;"> </span></span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span> return max + (-7 * x + y);</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>}</span></p>
<p style="margin-top: 0pt; margin-right: 0px; margin-bottom: 0pt; margin-left: 0in; color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0in; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; padding: 0px;"><span style="font-family: Calibri; font-size: 15px;"><span style="white-space: pre;"> </span>}</span></p>
<div><span style="font-family: Calibri; font-size: 15px;"><br /></span></div><img src ="http://www.cppblog.com/cokecoffe/aggbug/171483.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-04-15 16:44 <a href="http://www.cppblog.com/cokecoffe/archive/2012/04/15/171483.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>主题存放问题</title><link>http://www.cppblog.com/cokecoffe/archive/2012/02/22/166285.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 22 Feb 2012 14:46:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/02/22/166285.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/166285.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/02/22/166285.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/166285.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/166285.html</trackback:ping><description><![CDATA[<p>今天遇到一个问题，在写主题板块，共有21个主题类别方块，可以存放主题，但是主题数是&lt;=21的，所以想尽量不让空闲的板块连续，这样看起来以至于板块不那么空闲。</p> <p>于是想先从奇数中挑选位置，然后再从偶数位置挑选，这样能使空闲板块尽量不连续。</p> <p>例如：如果有5个板块，3个主题，那么在1，3，5的位置放入主题。</p> <p><a href="http://www.cppblog.com/images/cppblog_com/cokecoffe/Windows-Live-Writer/f341ef284a69_13DC7/QQ%E6%88%AA%E5%9B%BE20120222224330_2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="QQ截图20120222224330" border="0" alt="QQ截图20120222224330" src="http://www.cppblog.com/images/cppblog_com/cokecoffe/Windows-Live-Writer/f341ef284a69_13DC7/QQ%E6%88%AA%E5%9B%BE20120222224330_thumb.png" width="244" height="83"></a></p> <p>一个小Demo如下：</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>#include &lt;stdio.h&gt;</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">int</span> arrary[21] = {0,0,0};</pre><pre><span class="lnum">   4:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   5:  </span><span class="kwrd">int</span> ChooseAnEmpty()</pre><pre><span class="lnum">   6:  </span>{</pre><pre class="alt"><span class="lnum">   7:  </span>    <span class="kwrd">int</span> j = 0;</pre><pre><span class="lnum">   8:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   9:  </span>    <span class="kwrd">for</span>(j=1;j&lt;=21;j+=2)</pre><pre><span class="lnum">  10:  </span>    {</pre><pre class="alt"><span class="lnum">  11:  </span>        <span class="kwrd">if</span>(arrary[j] == 0)</pre><pre><span class="lnum">  12:  </span>        {</pre><pre class="alt"><span class="lnum">  13:  </span>            <span class="kwrd">return</span> j;</pre><pre><span class="lnum">  14:  </span>        }</pre><pre class="alt"><span class="lnum">  15:  </span>    }</pre><pre><span class="lnum">  16:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  17:  </span>    printf(<span class="str">"------\n"</span>);</pre><pre><span class="lnum">  18:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  19:  </span>    <span class="kwrd">for</span>(j=2;j&lt;=21;j+=2)</pre><pre><span class="lnum">  20:  </span>    {</pre><pre class="alt"><span class="lnum">  21:  </span>        <span class="kwrd">if</span>(arrary[j] == 0)</pre><pre><span class="lnum">  22:  </span>        {</pre><pre class="alt"><span class="lnum">  23:  </span>            <span class="kwrd">return</span> j;</pre><pre><span class="lnum">  24:  </span>        }</pre><pre class="alt"><span class="lnum">  25:  </span>    }</pre><pre><span class="lnum">  26:  </span>    </pre><pre class="alt"><span class="lnum">  27:  </span>    printf(<span class="str">"is full\n"</span>);</pre><pre><span class="lnum">  28:  </span>    <span class="kwrd">return</span> -1;</pre><pre class="alt"><span class="lnum">  29:  </span>}</pre><pre><span class="lnum">  30:  </span><span class="kwrd">int</span> main()</pre><pre class="alt"><span class="lnum">  31:  </span>{</pre><pre><span class="lnum">  32:  </span>    <span class="kwrd">int</span> i,pos;</pre><pre class="alt"><span class="lnum">  33:  </span>&nbsp;</pre><pre><span class="lnum">  34:  </span>    <span class="kwrd">for</span>(i = 0; i&lt;23; i++)</pre><pre class="alt"><span class="lnum">  35:  </span>    {</pre><pre><span class="lnum">  36:  </span>        pos = ChooseAnEmpty();</pre><pre class="alt"><span class="lnum">  37:  </span>        <span class="kwrd">if</span>(pos == -1)</pre><pre><span class="lnum">  38:  </span>        {</pre><pre class="alt"><span class="lnum">  39:  </span>            <span class="kwrd">break</span>;</pre><pre><span class="lnum">  40:  </span>        }    </pre><pre class="alt"><span class="lnum">  41:  </span>        printf(<span class="str">"empty pos = %d\n"</span>,pos);</pre><pre><span class="lnum">  42:  </span>        arrary[pos] = 1;</pre><pre class="alt"><span class="lnum">  43:  </span>    }</pre><pre><span class="lnum">  44:  </span>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><img src ="http://www.cppblog.com/cokecoffe/aggbug/166285.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-02-22 22:46 <a href="http://www.cppblog.com/cokecoffe/archive/2012/02/22/166285.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> meego开发的学习路线(转)</title><link>http://www.cppblog.com/cokecoffe/archive/2011/10/28/159290.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Fri, 28 Oct 2011 15:00:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2011/10/28/159290.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/159290.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2011/10/28/159290.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/159290.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/159290.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; font-size: x-small; ">转载时请注明出处和作者联系方式</span><span class="Apple-style-span" style="color: #333333; font-family: Arial, Console, Verdana, 'Courier New'; font-size: 12px; line-height: normal; background-color: #ffffff; "><div class="article_title" style="display: block; margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; color: #000000; font: normal normal normal 20px/30px 'Microsoft YaHei'; "><span class="ico ico_type_Original" style="display: inline-block; width: 19px; height: 19px; margin-top: 0px; margin-right: 2px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://static.blog.csdn.net/images/ico_Original.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: middle; background-position: 0px 0px; background-repeat: no-repeat no-repeat; "></span></div></span><span class="Apple-style-span" style="color: #333333; font-family: Arial, Console, Verdana, 'Courier New'; font-size: 12px; line-height: normal; background-color: #ffffff; "><div id="article_content" class="article_content" style="margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: 'Courier New', Console, Verdana, 微软雅黑; font: normal normal normal 14px/26px Arial; "><p><span style="font-size: small; "><span style="font-size: x-small; ">文章出处：</span><a href="http://blog.csdn.net/jack0106" style="color: #336699; text-decoration: none; "><span style="font-size: small; "><span style="font-size: x-small; ">http://blog.csdn.net/jack0106</span></span></a><span style="font-size: small; "><span style="font-size: x-small; ">&nbsp;<br />作者联系方式：冯牮&nbsp;</span></span><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#102;&#101;&#110;&#103;&#106;&#105;&#97;&#110;&#48;&#49;&#48;&#54;&#64;&#121;&#97;&#104;&#111;&#111;&#46;&#99;&#111;&#109;&#46;&#99;&#110;" style="color: #336699; text-decoration: none; "><span style="font-size: small; "><span style="font-size: x-small; ">fengjian0106@yahoo.com.cn</span></span></a></span></p><p>&nbsp;</p><p><span style="font-size: small; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;不同版本的meego系统，底层和中间层架构，大体是一致的，也是可以定制裁剪的。区别主要在最上层的用户体验层，比如handset版和notebook版的meego，UI就很不一样(UI的开发环境，也不一样)，这篇文档，是针对handset版meego的学习路线，做的一个总结。后面提高到的meego，未做明确说明的情况下，都是特指handset版的meego系统。</span></p><p>&nbsp;</p><p><span style="font-size: small; ">一、基础<br />1、编程语言</span></p><p><span style="font-size: small; "></span></p><p><br />1.1 meego的图形界面，是基于qt开发的，不用说，C++肯定是首选的开发语言。</p><p>1.2 STL的使用。qt自己实现了一套类STL接口，和标准的STL仅有一些小的区别，而且也有api文档。之所以单独提到STL，是因为这个东西太重要的，它的核心内容，就是容器和算法，这是c++程序中最基本的数据操作，一定要掌握。(初学者，可以通过STL的中文教程来学习，然后很容易就能转到qt的类stl接口上编写代码)。</p><p><br />1.3 meego是的中间层，不全是由qt开发的，其中的一部分，是由c语言写出来的。其实meego上很多中间层的服务程序，都是直接用的gnome桌面环境中的开源项目，而gnome的基础，就是基于c语言的gobject系统，所以，c语言也是一个重要的开发语言。<br />但是，c并不是必须的，如果懂c，相当于锦上添花，后面在第二部分，我会详细的解释。</p><p>&nbsp;</p><p>&nbsp;</p><p><span style="font-size: small; "></span></p><p><br />2、明确一些概念</p><p><br />2.1 首先明确一点，qt不仅仅是用来绘图的，qt其实是一个很完善的底层库，除了绘图，qt还融合了很多和UI无关的功能，比如网络、xml、sql等等，qt都有相关的类和框架。</p><p><br />2.2 meego是基于qt的，准确点描述，可以是这样：meego继承qt，开发了一套GUI库--libmeegotouch，meego的界面，就是用libmeegotouch开发的，而隐藏在界面背后的功能性的代码，则是用qt开发的。</p><p><br />2.3 qt有一个非常好的文档系统和众多的example code，一定要充分利用。</p><p><br />2.4 虽然libmeegotouch也有文档和example code，但是，由于libmeegotouch仅仅是负责绘制GUI，它的example code有局限性，而且数量也较少，因此对于开发人员，一定还要通过qt example code来深入学习。</p><p>&nbsp;</p><p>3、qt/meego基础学习</p><p><br />3.1 qmake的使用。qt程序使用qmake和pro文件进行工程管理。请看文档 qmake Tutorial --<a href="http://doc.qt.nokia.com/4.7/qmake-tutorial.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/qmake-tutorial.html</a></p><p><br />3.2 qt的对象系统。请看文档 Object Model --&nbsp;<a href="http://doc.qt.nokia.com/4.7/object.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/object.html</a><br />和 The Property System --&nbsp;<a href="http://doc.qt.nokia.com/4.7/properties.html#qt-s-property-system" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/properties.html#qt-s-property-system</a></p><p><br />3.3 qt中的信号和槽函数，这是qt的特色之一，是对c++扩充后的新概念。请看文档 Signals &amp; Slots --<a href="http://doc.qt.nokia.com/4.7/signalsandslots.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/signalsandslots.html</a></p><p><br />3.4 qt中的事件传递和主事件循环，请看文档 The Event System --<a href="http://doc.qt.nokia.com/4.7/eventsandfilters.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/eventsandfilters.html</a>&nbsp;和 Another Look at Events --&nbsp;<a href="http://doc.qt.nokia.com/qq/qq11-events.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/qq/qq11-events.html</a>，初学者可能会觉得这里很抽象，要理解事件循环，更基础的一个概念是文件的异步操作（select/poll/epoll 函数），这个可以随着开发的深入再慢慢体会。</p><p><br />3.5 qt中的容器类，这就是前面提到的qt中的类STL接口，请看文档 Container Classes --<a href="http://doc.qt.nokia.com/4.7/containers.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/containers.html</a></p><p>&nbsp;</p><p>4、meego/qt中的widget</p><p><br />4.1 不管是哪一种GUI库，都有widget的概念，相当于windows编程中的控件。按钮、文本编辑框、下拉菜单，这些都是widget，widget概念的引入，使得图形界面编程更加的方便快捷。</p><p><br />4.2 qt里面，有两套绘图系统，一套是QWidget+QLayoutItem系统，这个是桌面环境编程中使用的widget，另一套是Graphics View Framework，这套系统比xserver更灵活，可以对基本的图形元素做旋转操作，也初步实现了widget的父类QGraphicsWidget，但是并没有进一步实例化。<br />关于Graphics View Framework，请看文档 Graphics View Framework --<a href="http://doc.qt.nokia.com/4.7/graphicsview.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/graphicsview.html</a></p><p><br />4.3 meego是使用在小屏幕设备上的一个系统，如前所述，QWidget是为桌面环境设计的，不适合手持设备，虽然QGraphicsWidget并不完善，但是Graphics View Framework有很强的灵活性，所以meego选择从QGraphicsWidget继承，专门为小屏幕设备实现了一套widget库--MWidget。</p><p>QWidget和MWidget虽然是两套不同的widget，但是在设计理念和设计模式上，基本是相同的，尤其是layout系统，使用方法都是类似的。因此，如果已经熟悉QWidget了，则MWidget也可以很快的上手。如果是新手，则可以通过QWidget+QLayoutItem相关的技术文档来学习qt中layout的基本思路，然后再阅读MWidget的example code。下面给出一些参考文档，<br />Layout Management --&nbsp;<a href="http://doc.qt.nokia.com/4.7/layout.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/layout.html</a><br />Widgets and Layouts --&nbsp;<a href="http://doc.qt.nokia.com/4.7/widgets-and-layouts.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/widgets-and-layouts.html</a><br />MWidget Layout --&nbsp;<a href="http://apidocs.meego.com/1.1/platform/html/libmeegotouch/layouts.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/1.1/platform/html/libmeegotouch/layouts.html</a><br />Common Components&nbsp; --&nbsp;<a href="http://apidocs.meego.com/1.1/platform/html/index.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/1.1/platform/html/index.html</a></p><p><br />4.4 在熟悉了widget+layout的基本理念和使用方法后，就可以开始看meego的example code了，阅读libmeegotouch的源码目录中的example子目录中的代码，这是学习meego开发的最好的办法。首先推荐阅读的是example目录中的子目录&nbsp; tutorial_music_catalogue，关于这个代码，可以参考文档<a href="http://apidocs.meego.com/mtf/tutorial.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/mtf/tutorial.html</a>&nbsp;中的介绍。</p><p>&nbsp;</p><p>4.5 qt中的widget，数量巨多，很容易让人产生恐惧感。但是到了meego中，由于是为手持设备设计的，屏幕较小，widget的数量也少了很多，常用的widget，目前就只有10多个，像按钮、文本编辑框这一类widget，用法都很简单，很容易上手。唯一一个有一定难度的widget，就是MList，这个东西是手机上常用的一种widget，就是一个长的列表。MList使用了qt中的model/view framework，请看文档&nbsp;&nbsp;<a href="http://doc.qt.nokia.com/4.7/model-view-programming.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/model-view-programming.html</a>。libmeegotouch源码目录example中的子目录，apscanner，是一个使用了model/view框架的例子，要通过这个代码学习MList的使用。</p><p>&nbsp;</p><p>&nbsp;</p><p>5、meego/qt中常用的框架、技术</p><p><br />5.1 动画框架，qt提供了一个Animation Framework，可以让widget动起来（其实是让QObject动起来），请看文档 The Animation Framework --&nbsp;<a href="http://doc.qt.nokia.com/4.7/animation-overview.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/animation-overview.html</a></p><p><br />5.2 qt中的多线程，请看文档Thread Support in Qt --&nbsp;<a href="http://doc.qt.nokia.com/4.7/threads.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/threads.html</a></p><p><br />5.3 meego是为手持设备设计的，而现在流行的手机终端，都有触摸屏，qt中，也提供了对触摸屏手势的支持，请看文档&nbsp;<br />Gestures Programming --&nbsp;<a href="http://doc.qt.nokia.com/4.7/gestures-overview.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/gestures-overview.html</a><br />Gestures and Multitouch&nbsp; --&nbsp;<a href="http://apidocs.meego.com/1.1/platform/html/index.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/1.1/platform/html/index.html</a></p><p><br />5.4 meego中，为widget引入了css的概念，可以用css文件来控制MWidget的许多属性，请看文档 css in meego --&nbsp;<a href="http://apidocs.meego.com/1.1/platform/html/libmeegotouch/styling.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/1.1/platform/html/libmeegotouch/styling.html</a></p><p>5.5 meego的国际化处理，是基于qt的国际化方案的，请看文档&nbsp;<br />Internationalization with Qt --&nbsp;<a href="http://doc.qt.nokia.com/4.7/internationalization.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/internationalization.html</a><br />Internationalisation Guidelines --&nbsp;<a href="http://apidocs.meego.com/1.1/platform/html/libmeegotouch/i18n.html" style="color: #336699; text-decoration: none; ">http://apidocs.meego.com/1.1/platform/html/libmeegotouch/i18n.html</a></p><p>&nbsp;</p><p>二、深入<br />&nbsp;&nbsp;&nbsp;&nbsp; 前面的介绍，着重于meego开发的基本技能，尤其是widget的使用。隐藏在GUI后面的功能性代码的开发，meego也提供了很多优秀的编程框架。</p><p>1、进程间通信。linux桌面环境最常用的通信方式是dbus，而且dbus已经成为一个标准，meego自然也是使用dbus。</p><p>1.1 dbus原生是用c语言开发的，同时可以绑定到很多面向对象的编程语言之上，详细介绍，可以参考<a href="http://www.freedesktop.org/wiki/Software/dbus" style="color: #336699; text-decoration: none; ">http://www.freedesktop.org/wiki/Software/dbus</a></p><p><br />1.2 gnome桌面开发中，使用的是dbus-glib库，这个是基于gobject对象系统的c库，详细介绍，可以参考<a href="http://library.gnome.org/devel/dbus-glib/unstable/index.html" style="color: #336699; text-decoration: none; ">http://library.gnome.org/devel/dbus-glib/unstable/index.html</a></p><p><br />1.3 qt中也绑定了dbus，详细介绍，可以参考<a href="http://doc.qt.nokia.com/4.7/intro-to-dbus.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/4.7/intro-to-dbus.html</a></p><p>&nbsp;</p><p>2、数据库</p><p><br />2.1 meego平台上使用了一个中心数据库，tracker，这个也是gnome桌面项目中发展起来的一个技术，详细介绍，可以参考&nbsp;<a href="http://projects.gnome.org/tracker/" style="color: #336699; text-decoration: none; ">http://projects.gnome.org/tracker/</a></p><p><br />2.2 gnome桌面开发中，使用的是tracker库(基于dbus)，是基于gobject对象系统的c库，可以从<a href="http://ftp.gnome.org/pub/GNOME/sources/tracker/0.9/" style="color: #336699; text-decoration: none; ">http://ftp.gnome.org/pub/GNOME/sources/tracker/0.9/</a>&nbsp;下载</p><p><br />2.3 qt也对tracker做了一个绑定，有一个libqttracker库，可以从&nbsp;<a href="http://maemo.gitorious.org/maemo-af/libqttracker/trees/master" style="color: #336699; text-decoration: none; ">http://maemo.gitorious.org/maemo-af/libqttracker/trees/master</a>&nbsp;下载</p><p>&nbsp;</p><p>3、多媒体编程</p><p><br />3.1 qt有一套多媒体编程框架Phonon ，但是这并不是qt的最终目标。可以忽略这个框架。</p><p><br />3.2 qt现在有一个单独的项目，qt-mobility，其中有一个新的多媒体编程框架 Multimedia --<a href="http://doc.qt.nokia.com/qtmobility-1.1.0/multimedia.html" style="color: #336699; text-decoration: none; ">http://doc.qt.nokia.com/qtmobility-1.1.0/multimedia.html</a>，这个才是qt将会主推的方案，meego上也是用的这套框架。</p><p><br />3.3 如果只是开发音频/视频播放器，Multimedia已经足够了，它把很多编解码的细节都隐藏了，开发者可以集中精力开发用户体验。Multimedia的后端，使用的是gstreamer，gstreamer是gnome桌面项目中发展起来的一套多媒体编解码框架，是基于gobject对象系统的c库，可以参考<a href="http://www.gstreamer.net/" style="color: #336699; text-decoration: none; ">http://www.gstreamer.net/</a>&nbsp;，如果需要灵活的开发功能更复杂的多媒体程序，则可以使用gstreamer框架。</p><p>&nbsp;</p><p>4、即时通讯程序</p><p><br />4.1 gnome桌面项目中，发展了一个即时通讯的库，telepathy(基于dbus)，这是一个框架，可以把不同的即时通讯程序协议容括进来，可以参考&nbsp;<a href="http://telepathy.freedesktop.org/wiki/" style="color: #336699; text-decoration: none; ">http://telepathy.freedesktop.org/wiki/</a></p><p><br />4.2 原生的telepathy，是基于gobject开发的c库，可以参考&nbsp;<a href="http://telepathy.freedesktop.org/doc/telepathy-glib/" style="color: #336699; text-decoration: none; ">http://telepathy.freedesktop.org/doc/telepathy-glib/</a>和&nbsp;<a href="http://telepathy.freedesktop.org/doc/book/" style="color: #336699; text-decoration: none; ">http://telepathy.freedesktop.org/doc/book/</a></p><p><br />4.3 qt也绑定了telepathy，提供了一个c++接口，可以参考&nbsp;<a href="http://telepathy.freedesktop.org/doc/telepathy-qt4/" style="color: #336699; text-decoration: none; ">http://telepathy.freedesktop.org/doc/telepathy-qt4/</a></p><p>&nbsp;</p><p>5、meego开发中的c语言<br />从前面介绍的4个框架来看，原生都是用c语言开发的，而且都有基于gobject系统的c接口。qt做的，主要是对这类底层库的一个上层封装，或者是编程语言的绑定。对于开发者，在学习这些框架的时候，如果了解gobject系统，学习起来肯定会更方便，而且很多可以参考的文档，也都是以c语言的原生接口为例的，包括大量的example code，也是用c写的。所以，在开发过程中，基于gobject对象系统的c编程，是开发者的第二个有力工具。</p></div></span><img src ="http://www.cppblog.com/cokecoffe/aggbug/159290.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2011-10-28 23:00 <a href="http://www.cppblog.com/cokecoffe/archive/2011/10/28/159290.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>