哈理工 2139 魔幻菱形

来源:互联网 发布:全球人工智能金融峰会 编辑:程序博客网 时间:2024/04/27 21:51
魔幻菱形Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 246(172 users)Total Accepted: 179(165 users)Rating: Special Judge: NoDescription

图案输出总会让人不屑一顾,但是谁也不能保证在最短的时间内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;}


 

0 0
原创粉丝点击