<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>开心e点 &#187; exercise</title>
	<atom:link href="http://www.ebnd.cn/tag/exercise/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ebnd.cn</link>
	<description>好好学习 天天向上</description>
	<lastBuildDate>Tue, 21 Jun 2011 15:00:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>一道小题目-用*#@打印矩形</title>
		<link>http://www.ebnd.cn/2009/09/02/exercise-to-print-rectangle/</link>
		<comments>http://www.ebnd.cn/2009/09/02/exercise-to-print-rectangle/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 21:09:40 +0000</pubDate>
		<dc:creator>dandan</dc:creator>
				<category><![CDATA[曲不离口]]></category>
		<category><![CDATA[exercise]]></category>

		<guid isPermaLink="false">http://www.ebnd.cn/?p=61</guid>
		<description><![CDATA[前阵在 javaeye 上看到的一个题目，在这里记录下。 [题目] 补全printRect方法。 要求根据传入的宽和高打印出相应大小的矩形，矩形最外圈为*，内部用#和@交替填充 public void printRect&#40;int w,int h&#41; &#123; &#125; 预期效果： printRect&#40;21,9&#41;; ********************* *###################* *#@@@@@@@@@@@@@@@@@#* *#@###############@#* *#@#@@@@@@@@@@@@@#@#* *#@###############@#* *#@@@@@@@@@@@@@@@@@#* *###################* ********************* ↓ 写了个python的版本： def printRect&#40;w, h&#41;: for i in range&#40;1, h+1&#41;: for j in range&#40;1, w+1&#41;: p = min&#40; min&#40;j, w+1-j&#41;, min&#40;i, h+1-i&#41; &#41; if p == 1: print '*', elif p [...]]]></description>
			<content:encoded><![CDATA[<p>前阵在 javaeye 上看到的一个题目，在这里记录下。</p>
<p><br class="spacer_" /></p>
<p><strong>[题目]</strong> 补全printRect方法。</p>
<p>要求根据传入的宽和高打印出相应大小的矩形，矩形最外圈为*，内部用#和@交替填充</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> printRect<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> w,<span style="color: #000066; font-weight: bold;">int</span> h<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><br class="spacer_" /></p>
<p>预期效果：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">printRect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">21</span>,<span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">*********************</span>
<span style="color: #339933;">*</span>###################<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>#@@@@@@@@@@@@@@@@@#<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>#@###############@#<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>#@#@@@@@@@@@@@@@#@#<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>#@###############@#<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>#@@@@@@@@@@@@@@@@@#<span style="color: #339933;">*</span>
<span style="color: #339933;">*</span>###################<span style="color: #339933;">*</span>
<span style="color: #339933;">*********************</span></pre></div></div>

<p><br class="spacer_" /></p>
<p>↓</p>
<p><br class="spacer_" /></p>
<p>写了个python的版本：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> printRect<span style="color: black;">&#40;</span>w, h<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, h+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, w+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
                        p = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span> <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>j, w+<span style="color: #ff4500;">1</span>-j<span style="color: black;">&#41;</span>, <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>i, h+<span style="color: #ff4500;">1</span>-i<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> p == <span style="color: #ff4500;">1</span>:
                                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'*'</span>,
                        <span style="color: #ff7700;font-weight:bold;">elif</span> p <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">2</span> == <span style="color: #ff4500;">0</span>:
                                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'#'</span>,
                        <span style="color: #ff7700;font-weight:bold;">else</span>:
                                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'@'</span>,
                <span style="color: #ff7700;font-weight:bold;">print</span></pre></div></div>

<p><br class="spacer_" /></p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>无相关文章</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ebnd.cn/2009/09/02/exercise-to-print-rectangle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

