给定单词str,任务是使用*模式打印该单词的字母。
例子:
Input: GFG
Output:
******
*
*
*
* ****
* * *
* * *
*** *
*******
**
**
******
**
**
**
******
*
*
*
* ****
* * *
* * *
*** *
方法:一个简单的实现是为每个字母AZ形成模式并将其称为函数。
下面是上述方法的实现:
C++
// C Program to print the Alphabets
// of a Given Word using * pattern
#include
#include
char ch;
// Function to print the letter A
void a(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int a = 0; a < 8; a++) {
if (i == 0 && (a == 0 || a == 7))
printf(" ");
else if (a < 2 || a > 5) {
printf("%c", ch);
}
else if (i < 2 || (i > 3 && i < 5)) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter B
void b(void)
{
printf("\n");
for (int i = 0; i < 9; i++) {
printf(" %c%c", ch, ch);
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
printf("%c", ch);
else if (i == 1)
printf("%c", ch);
else if (i < 4 && i > 0
&& r > 3) {
printf("%c", ch);
}
else if (i == 4 && r < 5) {
printf("%c", ch);
}
else if (i > 4 && i < 7
&& r > 3) {
printf("%c", ch);
}
else if (i == 7) {
printf("%c", ch);
}
else if (i == 8 && r < 5) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter C
void c(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1))
printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o > 1)))
printf(" ");
else if (i == 7
&& (o <= 1))
printf(" ");
else {
printf("%c", ch);
}
}
printf("\n");
}
}
// Function to print the letter D
void d(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
{
printf(" %c", ch);
}
for (int o = 0; o < 8; o++) {
if (i == 0 && (o >= 6 - i))
printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6)))
printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6)))
printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o < 7))
printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6)))
printf(" ");
else if (i == 7
&& (o >= 6 - i + 7))
printf(" ");
else {
printf("%c", ch);
}
}
printf("\n");
}
}
// Function to print the letter E
void e(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
printf("%c", ch);
}
else if (i == 3 && j < 6) {
printf("%c", ch);
}
else if (i > 3 && i < 6
&& j < 2) {
printf("%c", ch);
}
else if (i == 6) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter F
void f(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
printf("%c", ch);
}
else if (i == 3 && j < 6) {
printf("%c", ch);
}
else if (i > 3 && i < 7
&& j < 2) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter G
void g(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 4 && o > 3
|| (o == 4 || o == 7)
&& i > 4) {
printf("%c", ch);
}
else if (i == 0 && (o <= 1))
printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
printf(" ");
else if (i == 6
&& (o == 0 || (o > 1)))
printf(" ");
else if (i == 7
&& (o <= 1 || o == 5
|| o == 6))
printf(" ");
else {
printf("%c", ch);
}
}
printf("\n");
}
}
// Function to print the letter H
void h(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int h = 0; h < 8; h++) {
if (h < 2 || h > 5) {
printf("%c", ch);
}
else if (i > 2 && i < 5) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter I
void i(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int t = 0; t < 8; t++) {
if ((i < 1 || i > 6)
&& t < 8) {
printf("%c", ch);
}
else if (i > 0 && t < 3)
printf(" ");
else if (i > 0 && t > 2
&& t < 5) {
printf("%c", ch);
}
else if (i > 0 && t > 4)
printf(" ");
else {
}
}
printf("\n");
}
}
// Function to print the letter J
void j(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int h = 0; h < 8; h++) {
if (i < 1) {
printf("%c", ch);
}
else if (i == 5 && h < 1) {
printf("%c", ch);
}
else if (i < 7 && h > 5) {
printf("%c", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
printf(" ");
else if (i > 5) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter K
void k(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int k1 = 0; k1 < 7; k1++) {
if (k1 < 2) {
printf("%c", ch);
}
else if ((k1 >= 5 - i)
&& (k1 <= 6 - i)) {
printf("%c", ch);
}
else if (i >= 4) {
if (k1 == i - 2 || k1 == i - 1) {
printf("%c", ch);
}
else
printf(" ");
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter L
void l(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
{
printf("%c%c", ch, ch);
}
if (i == 6) {
{
printf("%c%c", ch, ch);
}
{
printf("%c%c", ch, ch);
}
printf("%c%c", ch, ch);
}
if (i == 7) {
{
printf("%c%c", ch, ch);
}
{
printf("%c%c", ch, ch);
}
printf("%c%c", ch, ch);
}
printf("\n");
}
}
// Function to print the letter M
void m(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
printf("%c", ch);
}
else if (i < 4
&& (j == 7 - i || j == i)) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter N
void n(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int n = 0; n < 8; n++) {
if (n < 2 || n > 5) {
printf("%c", ch);
}
else if (i == n - 1
|| i == n + 1 || i == n) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter O
void o(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1 || o >= 6 - i))
printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
printf(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
printf(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
printf(" ");
else {
printf("%c", ch);
}
}
printf("\n");
}
}
// Function to print the letter P
void p(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
{
printf("%c%c", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
printf("%c", ch);
else if (i == 1)
printf("%c", ch);
else if (i < 4 && i > 0 && r > 3) {
printf("%c", ch);
}
else if (i == 4 && r < 5) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter Q
void q(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int o = 0; o < 8; o++) {
if (o == i)
printf("%c", ch);
else if (i == 0
&& (o <= 1 || o >= 6 - i))
printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
printf(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
printf(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
printf(" ");
else {
printf("%c", ch);
}
}
printf("\n");
}
}
// Function to print the letter R
void r(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
{
printf("%c%c", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
printf("%c", ch);
else if (i == 1)
printf("%c", ch);
else if (i < 4 && i > 0
&& r > 3) {
printf("%c", ch);
}
else if (i >= 4) {
if (i == 4
&& (r == 3 || r == 4)) {
printf("%c", ch);
}
else if (r == i - 2
|| r == i - 3) {
printf("%c", ch);
}
else
printf(" ");
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter S
void s(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0 && j > 0) {
printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
printf("%c", ch);
}
else if (i == 3 && j > 0
&& j < 6) {
printf("%c", ch);
}
else if (i > 3 && i < 6
&& j > 4) {
printf("%c", ch);
}
else if (i == 6 && j < 6) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter T
void t(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int t = 0; t < 8; t++) {
if (i < 2 && t < 8) {
printf("%c", ch);
}
if (i > 1 && t < 3)
printf(" ");
if (i > 1 && t > 2
&& t < 5) {
printf("%c", ch);
}
if (i > 1 && t > 4)
printf(" ");
}
printf("\n");
}
}
// Function to print the letter U
void u(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int h = 0; h < 8; h++) {
if (i < 7 && (h < 2 || h > 5)) {
printf("%c", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
printf(" ");
else if (i > 5) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter V
void v(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int v = 0; v < 8; v++)
if ((v == 0 || v == 7)
&& i < 4) {
printf("%c", ch);
}
else if ((v == i - 4 || v == 11 - i)
&& i >= 4) {
printf("%c", ch);
}
else
printf(" ");
printf("\n");
}
}
// Function to print the letter W
void w(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
printf("%c", ch);
}
else if (i > 3
&& (j == 7 - i || j == i)) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter X
void x(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int m = 0; m < 8; m++) {
if (i == m || m == 7 - i) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter Y
void y(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int y = 0; y < 8; y++) {
if (i < 4) {
if (y == i || y == i + 1
|| y == 6 - i || y == 7 - i) {
printf("%c", ch);
}
else
printf(" ");
}
else if (y == 3 || y == 4) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the letter Z
void z(void)
{
printf("\n");
for (int i = 0; i < 8; i++) {
printf(" ");
for (int j = 0; j < 8; j++) {
if (i == 0 || i == 7) {
printf("%c", ch);
}
else if (j == 7 - i) {
printf("%c", ch);
}
else
printf(" ");
}
printf("\n");
}
}
// Function to print the required pattern
// by taking out each characters in it
void printPattern(char* str)
{
int in = 0;
while (str[in]) {
char ch = str[in];
if (ch < 95)
ch = ch + 32;
switch (ch) {
case 'a':
a();
break;
case 'b':
b();
break;
case 'c':
c();
break;
case 'd':
d();
break;
case 'e':
e();
break;
case 'f':
f();
break;
case 'g':
g();
break;
case 'h':
h();
break;
case 'i':
i();
break;
case 'j':
j();
break;
case 'k':
k();
break;
case 'l':
l();
break;
case 'm':
m();
break;
case 'n':
n();
break;
case 'o':
o();
break;
case 'p':
p();
break;
case 'q':
q();
break;
case 'r':
r();
break;
case 's':
s();
break;
case 't':
t();
break;
case 'u':
u();
break;
case 'v':
v();
break;
case 'w':
w();
break;
case 'x':
x();
break;
case 'y':
y();
break;
case 'z':
z();
break;
default:
break;
}
in++;
}
}
// Driver code
int main()
{
ch = '*';
char* str = "GFG";
printPattern(str);
return 0;
}
Java
// Java Program to print the Alphabets
// of a Given Word using * pattern
class GFG{
static char ch;
// Function to print the letter A
static void a()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int a = 0; a < 8; a++) {
if (i == 0 && (a == 0 || a == 7))
System.out.printf(" ");
else if (a < 2 || a > 5) {
System.out.printf("%c", ch);
}
else if (i < 2 || (i > 3 && i < 5)) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter B
static void b()
{
System.out.printf("\n");
for (int i = 0; i < 9; i++) {
System.out.printf(" %c%c", ch, ch);
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
System.out.printf("%c", ch);
else if (i == 1)
System.out.printf("%c", ch);
else if (i < 4 && i > 0
&& r > 3) {
System.out.printf("%c", ch);
}
else if (i == 4 && r < 5) {
System.out.printf("%c", ch);
}
else if (i > 4 && i < 7
&& r > 3) {
System.out.printf("%c", ch);
}
else if (i == 7) {
System.out.printf("%c", ch);
}
else if (i == 8 && r < 5) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter C
static void c()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1))
System.out.printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
System.out.printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
System.out.printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
System.out.printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o > 1)))
System.out.printf(" ");
else if (i == 7
&& (o <= 1))
System.out.printf(" ");
else {
System.out.printf("%c", ch);
}
}
System.out.printf("\n");
}
}
// Function to print the letter D
static void d()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
{
System.out.printf(" %c", ch);
}
for (int o = 0; o < 8; o++) {
if (i == 0 && (o >= 6 - i))
System.out.printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6)))
System.out.printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6)))
System.out.printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o < 7))
System.out.printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6)))
System.out.printf(" ");
else if (i == 7
&& (o >= 6 - i + 7))
System.out.printf(" ");
else {
System.out.printf("%c", ch);
}
}
System.out.printf("\n");
}
}
// Function to print the letter E
static void e()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
System.out.printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
System.out.printf("%c", ch);
}
else if (i == 3 && j < 6) {
System.out.printf("%c", ch);
}
else if (i > 3 && i < 6
&& j < 2) {
System.out.printf("%c", ch);
}
else if (i == 6) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter F
static void f()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
System.out.printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
System.out.printf("%c", ch);
}
else if (i == 3 && j < 6) {
System.out.printf("%c", ch);
}
else if (i > 3 && i < 7
&& j < 2) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter G
static void g()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 4 && o > 3
|| (o == 4 || o == 7)
&& i > 4) {
System.out.printf("%c", ch);
}
else if (i == 0 && (o <= 1))
System.out.printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
System.out.printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
System.out.printf(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
System.out.printf(" ");
else if (i == 6
&& (o == 0 || (o > 1)))
System.out.printf(" ");
else if (i == 7
&& (o <= 1 || o == 5
|| o == 6))
System.out.printf(" ");
else {
System.out.printf("%c", ch);
}
}
System.out.printf("\n");
}
}
// Function to print the letter H
static void h()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int h = 0; h < 8; h++) {
if (h < 2 || h > 5) {
System.out.printf("%c", ch);
}
else if (i > 2 && i < 5) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter I
static void i()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int t = 0; t < 8; t++) {
if ((i < 1 || i > 6)
&& t < 8) {
System.out.printf("%c", ch);
}
else if (i > 0 && t < 3)
System.out.printf(" ");
else if (i > 0 && t > 2
&& t < 5) {
System.out.printf("%c", ch);
}
else if (i > 0 && t > 4)
System.out.printf(" ");
else {
}
}
System.out.printf("\n");
}
}
// Function to print the letter J
static void j()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int h = 0; h < 8; h++) {
if (i < 1) {
System.out.printf("%c", ch);
}
else if (i == 5 && h < 1) {
System.out.printf("%c", ch);
}
else if (i < 7 && h > 5) {
System.out.printf("%c", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
System.out.printf(" ");
else if (i > 5) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter K
static void k()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int k1 = 0; k1 < 7; k1++) {
if (k1 < 2) {
System.out.printf("%c", ch);
}
else if ((k1 >= 5 - i)
&& (k1 <= 6 - i)) {
System.out.printf("%c", ch);
}
else if (i >= 4) {
if (k1 == i - 2 || k1 == i - 1) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter L
static void l()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
{
System.out.printf("%c%c", ch, ch);
}
if (i == 6) {
{
System.out.printf("%c%c", ch, ch);
}
{
System.out.printf("%c%c", ch, ch);
}
System.out.printf("%c%c", ch, ch);
}
if (i == 7) {
{
System.out.printf("%c%c", ch, ch);
}
{
System.out.printf("%c%c", ch, ch);
}
System.out.printf("%c%c", ch, ch);
}
System.out.printf("\n");
}
}
// Function to print the letter M
static void m()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
System.out.printf("%c", ch);
}
else if (i < 4
&& (j == 7 - i || j == i)) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter N
static void n()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int n = 0; n < 8; n++) {
if (n < 2 || n > 5) {
System.out.printf("%c", ch);
}
else if (i == n - 1
|| i == n + 1 || i == n) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter O
static void o()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1 || o >= 6 - i))
System.out.printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
System.out.printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
System.out.printf(" ");
else {
System.out.printf("%c", ch);
}
}
System.out.printf("\n");
}
}
// Function to print the letter P
static void p()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
{
System.out.printf("%c%c", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
System.out.printf("%c", ch);
else if (i == 1)
System.out.printf("%c", ch);
else if (i < 4 && i > 0 && r > 3) {
System.out.printf("%c", ch);
}
else if (i == 4 && r < 5) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter Q
static void q()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int o = 0; o < 8; o++) {
if (o == i)
System.out.printf("%c", ch);
else if (i == 0
&& (o <= 1 || o >= 6 - i))
System.out.printf(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
System.out.printf(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
System.out.printf(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
System.out.printf(" ");
else {
System.out.printf("%c", ch);
}
}
System.out.printf("\n");
}
}
// Function to print the letter R
static void r()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
{
System.out.printf("%c%c", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
System.out.printf("%c", ch);
else if (i == 1)
System.out.printf("%c", ch);
else if (i < 4 && i > 0
&& r > 3) {
System.out.printf("%c", ch);
}
else if (i >= 4) {
if (i == 4
&& (r == 3 || r == 4)) {
System.out.printf("%c", ch);
}
else if (r == i - 2
|| r == i - 3) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter S
static void s()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 7; j++) {
if (i == 0 && j > 0) {
System.out.printf("%c", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
System.out.printf("%c", ch);
}
else if (i == 3 && j > 0
&& j < 6) {
System.out.printf("%c", ch);
}
else if (i > 3 && i < 6
&& j > 4) {
System.out.printf("%c", ch);
}
else if (i == 6 && j < 6) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter T
static void t()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int t = 0; t < 8; t++) {
if (i < 2 && t < 8) {
System.out.printf("%c", ch);
}
if (i > 1 && t < 3)
System.out.printf(" ");
if (i > 1 && t > 2
&& t < 5) {
System.out.printf("%c", ch);
}
if (i > 1 && t > 4)
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter U
static void u()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int h = 0; h < 8; h++) {
if (i < 7 && (h < 2 || h > 5)) {
System.out.printf("%c", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
System.out.printf(" ");
else if (i > 5) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter V
static void v()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int v = 0; v < 8; v++)
if ((v == 0 || v == 7)
&& i < 4) {
System.out.printf("%c", ch);
}
else if ((v == i - 4 || v == 11 - i)
&& i >= 4) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
System.out.printf("\n");
}
}
// Function to print the letter W
static void w()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
System.out.printf("%c", ch);
}
else if (i > 3
&& (j == 7 - i || j == i)) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter X
static void x()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int m = 0; m < 8; m++) {
if (i == m || m == 7 - i) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter Y
static void y()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int y = 0; y < 8; y++) {
if (i < 4) {
if (y == i || y == i + 1
|| y == 6 - i || y == 7 - i) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
else if (y == 3 || y == 4) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the letter Z
static void z()
{
System.out.printf("\n");
for (int i = 0; i < 8; i++) {
System.out.printf(" ");
for (int j = 0; j < 8; j++) {
if (i == 0 || i == 7) {
System.out.printf("%c", ch);
}
else if (j == 7 - i) {
System.out.printf("%c", ch);
}
else
System.out.printf(" ");
}
System.out.printf("\n");
}
}
// Function to print the required pattern
// by taking out each characters in it
static void printPattern(char[] str)
{
int in = 0;
while (in
C#
// C# Program to print the Alphabets
// of a Given Word using * pattern
using System;
class GFG{
static char ch;
// Function to print the letter A
static void a()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int a = 0; a < 8; a++) {
if (i == 0 && (a == 0 || a == 7))
Console.Write(" ");
else if (a < 2 || a > 5) {
Console.Write("{0}", ch);
}
else if (i < 2 || (i > 3 && i < 5)) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter B
static void b()
{
Console.Write("\n");
for (int i = 0; i < 9; i++) {
Console.Write(" {0}{0}", ch, ch);
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
Console.Write("{0}", ch);
else if (i == 1)
Console.Write("{0}", ch);
else if (i < 4 && i > 0
&& r > 3) {
Console.Write("{0}", ch);
}
else if (i == 4 && r < 5) {
Console.Write("{0}", ch);
}
else if (i > 4 && i < 7
&& r > 3) {
Console.Write("{0}", ch);
}
else if (i == 7) {
Console.Write("{0}", ch);
}
else if (i == 8 && r < 5) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter C
static void c()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1))
Console.Write(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
Console.Write(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
Console.Write(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
Console.Write(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o > 1)))
Console.Write(" ");
else if (i == 7
&& (o <= 1))
Console.Write(" ");
else {
Console.Write("{0}", ch);
}
}
Console.Write("\n");
}
}
// Function to print the letter D
static void d()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
{
Console.Write(" {0}", ch);
}
for (int o = 0; o < 8; o++) {
if (i == 0 && (o >= 6 - i))
Console.Write(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6)))
Console.Write(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6)))
Console.Write(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o < 7))
Console.Write(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6)))
Console.Write(" ");
else if (i == 7
&& (o >= 6 - i + 7))
Console.Write(" ");
else {
Console.Write("{0}", ch);
}
}
Console.Write("\n");
}
}
// Function to print the letter E
static void e()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
Console.Write("{0}", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
Console.Write("{0}", ch);
}
else if (i == 3 && j < 6) {
Console.Write("{0}", ch);
}
else if (i > 3 && i < 6
&& j < 2) {
Console.Write("{0}", ch);
}
else if (i == 6) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter F
static void f()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 7; j++) {
if (i == 0) {
Console.Write("{0}", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
Console.Write("{0}", ch);
}
else if (i == 3 && j < 6) {
Console.Write("{0}", ch);
}
else if (i > 3 && i < 7
&& j < 2) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter G
static void g()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int o = 0; o < 8; o++) {
if (i == 4 && o > 3
|| (o == 4 || o == 7)
&& i > 4) {
Console.Write("{0}", ch);
}
else if (i == 0 && (o <= 1))
Console.Write(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o > 1)))
Console.Write(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o > 1)))
Console.Write(" ");
else if ((i == 3 || i == 4
|| i == 5)
&& (o > 0))
Console.Write(" ");
else if (i == 6
&& (o == 0 || (o > 1)))
Console.Write(" ");
else if (i == 7
&& (o <= 1 || o == 5
|| o == 6))
Console.Write(" ");
else {
Console.Write("{0}", ch);
}
}
Console.Write("\n");
}
}
// Function to print the letter H
static void h()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int h = 0; h < 8; h++) {
if (h < 2 || h > 5) {
Console.Write("{0}", ch);
}
else if (i > 2 && i < 5) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter I
static void i()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int t = 0; t < 8; t++) {
if ((i < 1 || i > 6)
&& t < 8) {
Console.Write("{0}", ch);
}
else if (i > 0 && t < 3)
Console.Write(" ");
else if (i > 0 && t > 2
&& t < 5) {
Console.Write("{0}", ch);
}
else if (i > 0 && t > 4)
Console.Write(" ");
else {
}
}
Console.Write("\n");
}
}
// Function to print the letter J
static void j()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int h = 0; h < 8; h++) {
if (i < 1) {
Console.Write("{0}", ch);
}
else if (i == 5 && h < 1) {
Console.Write("{0}", ch);
}
else if (i < 7 && h > 5) {
Console.Write("{0}", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
Console.Write(" ");
else if (i > 5) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter K
static void k()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int k1 = 0; k1 < 7; k1++) {
if (k1 < 2) {
Console.Write("{0}", ch);
}
else if ((k1 >= 5 - i)
&& (k1 <= 6 - i)) {
Console.Write("{0}", ch);
}
else if (i >= 4) {
if (k1 == i - 2 || k1 == i - 1) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter L
static void l()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
{
Console.Write("{0}{0}", ch, ch);
}
if (i == 6) {
{
Console.Write("{0}{0}", ch, ch);
}
{
Console.Write("{0}{0}", ch, ch);
}
Console.Write("{0}{0}", ch, ch);
}
if (i == 7) {
{
Console.Write("{0}{0}", ch, ch);
}
{
Console.Write("{0}{0}", ch, ch);
}
Console.Write("{0}{0}", ch, ch);
}
Console.Write("\n");
}
}
// Function to print the letter M
static void m()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
Console.Write("{0}", ch);
}
else if (i < 4
&& (j == 7 - i || j == i)) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter N
static void n()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int n = 0; n < 8; n++) {
if (n < 2 || n > 5) {
Console.Write("{0}", ch);
}
else if (i == n - 1
|| i == n + 1 || i == n) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter O
static void o()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int o = 0; o < 8; o++) {
if (i == 0 && (o <= 1 || o >= 6 - i))
Console.Write(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
Console.Write(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
Console.Write(" ");
else {
Console.Write("{0}", ch);
}
}
Console.Write("\n");
}
}
// Function to print the letter P
static void p()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
{
Console.Write("{0}{0}", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
Console.Write("{0}", ch);
else if (i == 1)
Console.Write("{0}", ch);
else if (i < 4 && i > 0 && r > 3) {
Console.Write("{0}", ch);
}
else if (i == 4 && r < 5) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter Q
static void q()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int o = 0; o < 8; o++) {
if (o == i)
Console.Write("{0}", ch);
else if (i == 0
&& (o <= 1 || o >= 6 - i))
Console.Write(" ");
else if (i == 1
&& (o == 0 || o == 8 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if (i == 2
&& (o == 1 || o == 8 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if ((i == 3 || i == 4 || i == 5)
&& (o > 0 && o < 7))
Console.Write(" ");
else if (i == 6
&& (o == 0 || o == 8 + 5 - i
|| (o < 6 && o > 1)))
Console.Write(" ");
else if (i == 7
&& (o <= 1 || o >= 6 - i + 7))
Console.Write(" ");
else {
Console.Write("{0}", ch);
}
}
Console.Write("\n");
}
}
// Function to print the letter R
static void r()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
{
Console.Write("{0}{0}", ch, ch);
}
for (int r = 0; r < 6; r++) {
if (i == 0 && r < 5)
Console.Write("{0}", ch);
else if (i == 1)
Console.Write("{0}", ch);
else if (i < 4 && i > 0
&& r > 3) {
Console.Write("{0}", ch);
}
else if (i >= 4) {
if (i == 4
&& (r == 3 || r == 4)) {
Console.Write("{0}", ch);
}
else if (r == i - 2
|| r == i - 3) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter S
static void s()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 7; j++) {
if (i == 0 && j > 0) {
Console.Write("{0}", ch);
}
else if (i > 0 && i < 3
&& j < 2) {
Console.Write("{0}", ch);
}
else if (i == 3 && j > 0
&& j < 6) {
Console.Write("{0}", ch);
}
else if (i > 3 && i < 6
&& j > 4) {
Console.Write("{0}", ch);
}
else if (i == 6 && j < 6) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter T
static void t()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int t = 0; t < 8; t++) {
if (i < 2 && t < 8) {
Console.Write("{0}", ch);
}
if (i > 1 && t < 3)
Console.Write(" ");
if (i > 1 && t > 2
&& t < 5) {
Console.Write("{0}", ch);
}
if (i > 1 && t > 4)
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter U
static void u()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int h = 0; h < 8; h++) {
if (i < 7 && (h < 2 || h > 5)) {
Console.Write("{0}", ch);
}
else if (i == 7
&& (h == 0 || h == 7))
Console.Write(" ");
else if (i > 5) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter V
static void v()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int v = 0; v < 8; v++)
if ((v == 0 || v == 7)
&& i < 4) {
Console.Write("{0}", ch);
}
else if ((v == i - 4 || v == 11 - i)
&& i >= 4) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
Console.Write("\n");
}
}
// Function to print the letter W
static void w()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 8; j++) {
if (j == 0 || j == 7) {
Console.Write("{0}", ch);
}
else if (i > 3
&& (j == 7 - i || j == i)) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter X
static void x()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int m = 0; m < 8; m++) {
if (i == m || m == 7 - i) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter Y
static void y()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int y = 0; y < 8; y++) {
if (i < 4) {
if (y == i || y == i + 1
|| y == 6 - i || y == 7 - i) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
else if (y == 3 || y == 4) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the letter Z
static void z()
{
Console.Write("\n");
for (int i = 0; i < 8; i++) {
Console.Write(" ");
for (int j = 0; j < 8; j++) {
if (i == 0 || i == 7) {
Console.Write("{0}", ch);
}
else if (j == 7 - i) {
Console.Write("{0}", ch);
}
else
Console.Write(" ");
}
Console.Write("\n");
}
}
// Function to print the required pattern
// by taking out each characters in it
static void printPattern(char[] str)
{
int iN = 0;
while (iN
输出:
******
*
*
*
* ****
* * *
* * *
*** *
*******
**
**
******
**
**
**
******
*
*
*
* ****
* * *
* * *
*** *
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。