哈理工 2139 魔幻菱形

魔幻菱形
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 246(172 users) Total Accepted: 179(165 users) Rating: Special Judge: No
Description

图案输出总会让人不屑一顾,但是谁也不能保证在最短的时间内AC。

Input

多组数据测试。

每组数据有一个整数n,表示菱形高度。(n >= 3&& n为奇数)

Output

 输出高度为n的横向挨着的2个菱形。

Sample Input

7

Sample Output

   *      *

  ***    ***

 *****  *****

**************

 *****  *****

  ***    ***

   *      *

Source

2014暑假集训练习赛(7月30日)

 

 

打印菱形挺简单的 ,找关系就好了

#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<=n/2;i++)
        {
            for(int x=0;x<n/2-i;x++)
                cout<<" ";

            for(int j=n/2-i;j<=n/2+i;j++)
                cout<<"*";
                for(int y=n/2+i+1;y<n+n/2-i;y++)
                    cout<<" ";
            for(int k=n+n/2-i;k<=n/2+n+i;k++)
                cout<<"*";
            cout<<endl;
        }
        for(int m=1;m<=n/2;m++)//        {
           {
               for(int l=0;l<m;l++)
               cout<<" ";
               for(int t=m;t<n-m;t++)
               cout<<"*";
               for(int d=n-m+1;d<=n+m;d++)
                cout<<" ";
               for(int e=n+m;e<2*n-m;e++)
                cout<<"*";
               cout<<endl;

           }
      }

    return 0;
}


 

posted @ 2015-05-22 00:02  cbam  阅读(90)  评论(0)    收藏  举报