English 中文(简体)
参考星号(*)
原标题:draw X letter shape using asterisk(*)

i 想用星号(*)书写X字母形形体的方案。

#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
  int i, j;

  for(i = 1; i <= 9; i++){
    for(j = 1; j <= 12; j++){
      if(i == j){
        cout << "***";
      }else{
        cout << " ";
      }
    }
    cout<< endl;
  }

  return 0;
}

一) 方案规划非常新

i 仅作()我如何做整个X。

***------***
-***----***-
--***--***--
---******---
--***--***--
-***----***-
***------***  

that

include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int i, d, a=1,b=12,c;
for(i = 1; i <= 6; i++)
{
for (d=1; d<i;d++)  {cout <<" ";}
cout<<"***";
for (c=a+1; c<b;c++) {cout <<" ";}
{cout<<"***";}
for(b=12-i;b<i;b++) 
{cout<<"***";}
cout<<endl;
a++;
}
return 0;
}       

i divided the top of the (//) to three parts [space][][space][]

问题回答

I have written the following function/method in java. You can convert it to c++;

public static void printX(int x) {
    char[] chars = new char[x];
    for (int i = 0; i < x; i++) {
        chars[i] =  * ;
        chars[x - 1 - i] =  * ;
        for (int j = 0; j < x; j++) {
            if (j == i || j == (x - 1 - i)) {
                continue;
            }
            chars[j] =    ;
        }
        System.out.println(new String(chars));
    }

}

如果您称上述职能/方法为印刷X(5); 产出将达到5x5的大小,并包含X特性。

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

Firstly, pardon my very uneven X. For you as a beginner I would give out an algo for you to ponder upon rather than spoon feeding a code.

  • The interpreter does not know how to come back to a line which has already been printer. Therefore, you would have to draw both sides of the X in one iteration of the loop.

  • 之后,你会减少(星号-)和线2。

  • 直至星号为0时的中度。

  • 当你的代码显示星体为0时,则从同一航道开始,但每座星体的这种时光是++。

  • 在我的案件中,这已反复出现,直到开始计算饥饿,即4。

如果你有任何问题可以在现场张贴你的法典:

您应积极评估各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各道。 在纸面纸面上手工设计成图,并试图创造功能,这就把具体行所需空间的数量和回报作为理由。 例如:

*   *
 * * 
  *
 * *
*   *

每一行的面积等于:

0 [*] 3 [*]
1 [*] 1 [*]
2 [*] 
1 [*] 1 [*]
0 [*] 3 [*]

请注意,在每一行内,你需要两处休息室:先是初步和中间空间。

我20年前(我仍在学习时)所写的解决办法:

  • Make an line-column array, e.g. char screen[80][25];
  • Clear it by setting all entries to
  • "Draw a point" at x,y by setting screen[x][y]= * ;
  • When done, render the whole screen[80][25] by calling cout 2080 times. (2000 times for the characters and and 80 times for endl)

您知道如何提取<条码>。 你们可以很容易地加以调整。 但是,如果采用我的方法,你可以在同一<条码>中提取一个<>>>>>。 在您重新工作时,您在最后一行的<代码>/和:X上就座。

我使用了这种方法,因为我们不得不走一个圈子,这实际上更加困难。 是的,现在的缩略语一号可能使用<代码>std:vector<std:string> 屏幕,但背后的屏幕实际上是80x25 :

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
int  i, d, a=1,b=12,c ,e=1;
        for(i = 1; i <= 6; i++)
            {
                for (d=1; d<i;d++) {cout <<" ";}
                cout<<"***";
                for (c=a+1; c<b;c++) {cout <<" ";}
                {cout<<"***";}
                for(b=12-i;b<i;b++) 
                {cout<<"***";}
                cout<<endl;
                a++;
        }
for( i = 1; i <= 3; i++)
        {
            for ( d=6; d>i;d--) {cout <<" ";}
            cout<<"***";
            for (c=0; c<e-1;c++) {cout <<"  ";}
            {cout<<"***";}
            cout<<endl;
            e++;
    }

return 0;
}   
int n=11,i=0,k=0,j=0;
for(i=0;i<n;i++)
{
if(i<(n/2)) 
 {
    cout<<endl;
    for(j=0;j<i;j++)
    {
        cout<<" ";
    }
    cout<<"*";
    for(k=n/2;k>i;k--)
    {
        cout<<"  ";
    }
    cout<<"*";
 }
else
 {
    cout<<endl;
    for(k=n-1;k>i;k--)
    {
        cout<<" ";
    }
    cout<<"*";
    for(j=n/2;j<i;j++)
    {
        cout<<"  ";
    }
    cout<<"*";
 }  
}
#include<iostream>
using namespace std;
int main()
{
    int i, j;
    for(i = 1;i<= 5;i++)
    {
        for(j = 1;j<= 5;j++)
        {
            if((i == j)||(j==(5+1)-i))
            {
                cout << "*";
            }
            else{   
                cout << " ";
            }
        }
        cout<< endl;
    }
    system("pause");
}
#include "stdafx.h"
#include <iostream>
using namespace std;;


int _tmain(int argc, _TCHAR* argv[])
{
    int i,k,j;
    for (i=1;i<8;i++)
    {
        for (int k=0;k<i;k++)
        {
            cout<<" ";
        }
        cout<<"*";
        for (int k=8;k>i;k--)
        {
            cout<<"  ";
        }
        cout<<"*";
        cout<<endl;
    }
    for (i=1;i<8;i++)
    {
        for (int k=8;k>i;k--)
        {
            cout<<" ";
        }
        cout<<"*";

        for (int k=0;k<i;k++)
        {
            cout<<"  ";
        }
        cout<<" *";
        cout<<endl;
    }

    system("Pause");
    return 0;
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签