C shape 是什么

Python024

C shape 是什么,第1张

不是C shape是C#(C Sharp)是微软(Microsoft)为.NET Framework量身订做的程序语言,C#拥有C/C++的强大功能以及Visual Basic简易使用的特性,是第一个组件导向(Component-oriented)的程序语言,和C++与Java一样亦为对象导向(object-oriented)程序语言。 http://baike.baidu.com/view/107979.htm?fr=ala0_1

/*下面的程序是菱形打印的【终结者】,

改变下设置,就基本可以满足所有菱形打印的题目。

程序主体 for 语句只有9行,简单而强大

*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

// 这个小函数用来输出 repeatTimes 个字符 c

void printChar(char c,int repeatTimes)

{

int i

for(i=0i<repeatTimesi++)

printf("%c",c)

}

/*

特别的函数,获取当前要打印的下一个菱形图案

height : 菱形的高

shapeVariantStep : 变化的步数

baseShape : 菱形的基本图案

row : 当前打印的菱形图案的行坐标。

col : 当前打印的菱形图案的列坐标。

*/

char _buffer_[2]={0}

char* getShape(int height,int shapeVariantStep,char baseShape[],int row,int col)

{

int first = baseShape[0],last = first +(height-1)/2*shapeVariantStep

if(shapeVariantStep==0 || strlen(baseShape)!=1)

return baseShape

else

{

if( first>='0'&&first<='9'&&last<='9' ||

first>='a'&&first<='z'&&last<='z' ||

first>='A'&&first<='Z'&&last<='Z'

)

{

_buffer_[0] = first + ((height-2*abs(row)-1)/2 - abs(col))*shapeVariantStep

_buffer_[1] = '\0'

return _buffer_

}

else

{

return baseShape

}

}

}

int main(int argc, char *argv[])

{

// 菱形的图案

char shape[]="*"

// 菱形图案间的空白图案

char space=' '

// 每个图案之间的最小间隔(以一个字符为单位,不足用空白图案填充)

int interval=5

// 菱形的高(要求是奇数)

int height=7

// 菱形是否空心(只有边上的图案)。是:1,否 0

int isHollow=0

/* 特别的参数:设定菱形的图案是变化。

只有指定 shape 为 :

"0","1",...,"9",

或者 "a","b",...,"z",

或者 "A","B",...,"Z" 其中之一,

并且要保证从指定图形开始,后面至少还有连续的:

(height-1)/2*shapevariantStep

个可选的图形,菱形的图形才会是可变的。

*/

int shapeVariantStep = 0

int i,j,k,n

interval = interval <strlen(shape)?strlen(shape):interval

for(i=-(height-1)/2i<=(height-1)/2i++)

{

// 用来输出每行前的空白

printChar(space,abs(i)*interval)

// 这个 for(j) 语句用来输出每行的菱形图案

for(j=-(height-2*abs(i)-1)/2j<=(height-2*abs(i)-1)/2j++)

{

// 如果是非空心,输出所有图案;否则只输出两端的图案。

if(!isHollow || (isHollow &&(j==0 || j==height-2*abs(i)-1)))

{

n=printf("%s",getShape(height,shapeVariantStep,shape,i,j))

// 补齐为到宽度为 interval

printChar(space,interval-n)

}

// 对于空心的菱形,在本应该输出图案的地方,输出空白。

else

{

printChar(space,interval)

}

}

// 这个 for(j) 语句用来输出每行后的空白

printChar(space,abs(i)*interval)

printf("\n")

}

return 0

}

/*

运行结果:

shape[]="*"

space[]=" "

interval=5

height=7

isHollow=0

shapevariantStep = 0

*

* * *

* * * * *

* * * * * * *

* * * * *

* * *

*

shape[]="**"

space[]=" "

interval=5

height=7

isHollow=0

shapevariantStep = 0

**

** ** **

** ** ** ** **

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

** ** ** ** **

** ** **

**

shape[]="*"

space[]=" "

interval=5

height=7

isHollow=0

shapevariantStep = 0

...............*...................

..........*....*....*..............

.....*....*....*....*....*.........

*....*....*....*....*....*....*....

.....*....*....*....*....*.........

..........*....*....*..............

...............*...................

shape[]="*"

space[]=" "

interval=0

height=7

isHollow=0

shapevariantStep = 0

*

***

*****

*******

*****

***

*

shape[]="*"

space[]=" "

interval=5

height=11

isHollow=0

shapevariantStep = 0

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *

* * * * * * * * * * *

* * * * * * * * *

* * * * * * *

* * * * *

* * *

*

shape[]="*"

space[]=" "

interval=5

height=7

isHollow=1

shapevariantStep = 0

*

* *

* *

* *

* *

* *

*

shape[]="A"

space[]=" "

interval=5

height=17

isHollow=0

shapevariantStep = 1

A

A B A

A B C B A

A B C D C B A

A B C D E D C B A

A B C D E F E D C B A

A B C D E F G F E D C B A

A B C D E F G H G F E D C B A

A B C D E F G H I H G F E D C B A

A B C D E F G H G F E D C B A

A B C D E F G F E D C B A

A B C D E F E D C B A

A B C D E D C B A

A B C D C B A

A B C B A

A B A

A

shape[]="a"

space[]=" "

interval=5

height=17

isHollow=0

shapevariantStep = 1

a

a b a

a b c b a

a b c d c b a

a b c d e d c b a

a b c d e f e d c b a

a b c d e f g f e d c b a

a b c d e f g h g f e d c b a

a b c d e f g h i h g f e d c b a

a b c d e f g h g f e d c b a

a b c d e f g f e d c b a

a b c d e f e d c b a

a b c d e d c b a

a b c d c b a

a b c b a

a b a

a

shape[]="1"

space[]=" "

interval=5

height=9

isHollow=0

shapevariantStep = 2

1

1 3 1

1 3 5 3 1

1 3 5 7 5 3 1

1 3 5 7 9 7 5 3 1

1 3 5 7 5 3 1

1 3 5 3 1

1 3 1

1

*/