当前位置: 代码迷 >> C语言 >> 来做个简单的题
  详细解决方案

来做个简单的题

热度:217   发布时间:2006-08-10 09:29:31.0
以下是引用yu_hua在2006-8-10 8:51:55的发言:

#include<stdio.h>
#include<conio.h>
main( )
{
char i,j,k,s[]=" A ";
k=getchar();
for(i='A';i<=k;i++)
for(puts(s),j=1;s[j];j++)
if(s[j]!=' ')++s[j];
else if(s[j+1]=='A')s[j]='A';
else if(s[j-1]=='B')s[j]='A';
getch();
}


不错..只可惜还不够动态


----------------解决方案--------------------------------------------------------
♂♂♂

什么叫动态?

----------------解决方案--------------------------------------------------------
[CODE]#include <cstdlib>
#include <iostream>
using namespace std;

void f(char ch, int n)
{
if(ch>'A') f(ch-1, n+1);

for(int i=0; i<n; i++)
cout<<' ';
for(char t='A'; t<ch; t++)
cout<<t;
for(char t=ch; t>='A'; t--)
cout<<t;
for(int i=0; i<n; i++)
cout<<' ';

cout<<endl;
}

int main(int argc, char *argv[])
{
char ch;

while(cin>>ch)
f(ch,0);

system("PAUSE");
return EXIT_SUCCESS;
}[/CODE]


----------------解决方案--------------------------------------------------------
第四个for多余了

----------------解决方案--------------------------------------------------------
晕了

----------------解决方案--------------------------------------------------------
/*请用TC 2.0编译*/
#include&lt;ctype.h&gt;
main( )
{
     char i,j,k,s[53]="";
     while(isalpha(k=toupper(getch())))
     {
         memset(s,' ',52);
         for(s[26]=i='A';i&lt;=k;i++)
         for(puts(s),j=1;s[j];j++)
          if(s[j]!=' ')++s[j];
          else if(s[j+1]=='A')s[j]='A';
          else if(s[j-1]=='B')s[j]='A';
     }
}

运行时输入
1个X,或2个L,或3个H
将看见24层的金字塔
或两座12层的金字塔
或三座 8层的金字塔

----------------解决方案--------------------------------------------------------

楼主要的是金字塔..19楼的给你改了下

#include"stdio.h"
main()
{ int i,j,n,m,t=0;
char c,a='A';
c=getchar();
m=c-'A'+1;
n=m*2-1;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
if(j>m-i&&j<=m+t)
if(j<=m)printf("%c",a++);
else printf("%c",--a-1);
else printf(" ");
}
printf("\n");
a='A';
t++;
}
getch();
}

我自学还没学到数组...所以......


----------------解决方案--------------------------------------------------------
以下是引用SunShining在2006-8-7 19:00:53的发言:

#include<stdio.h>
char a=0,b,c,d=65,e=0,f=1,g=0;
main(){a==0?a=getchar(),getchar(),b=c=a-65:1;c>0&&e==0?putchar(' '),c--:(e=1,g<f?putchar(d++),g++,a=1:(a==1?d-=2,a=-1:d--,d>64?putchar(d):(putchar(10),e=0,g=0,d=65,f++,b--,c=b)));b==-1?a=0,f=1,main():main();}

老K呢..来玩一个,

俺没想到好算法,你有没


咦,在这里跟偶叫板

int i,h,k,u;
main(_){main(_,i?printf("%c",i>h/2?k++:k--,i--):(printf("\n%*c",40-(i=_++),' ',_>u-'@'&&exit()),k='A',i*=2,h=--i),_==1&&(i=!scanf(" %c",&u)));}
----------------解决方案--------------------------------------------------------
偶还能再减几个
----------------解决方案--------------------------------------------------------

哈哈..俺的也能减.只不过你没来.俺减去也无聊.不过.你的算法好象蛮变态的

看看日期..我都写上几天了.你才冒出来.莫非因为今天那台风的关系


----------------解决方案--------------------------------------------------------
  相关解决方案