CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

求一简单程序....

楼主gxnet12(及郁闷)2005-05-29 19:52:43 在 C/C++ / C语言 提问

好久没有碰C啦..今天一个朋友问一个简单的问题都记不起哒  
  请各位帮帮忙...小弟感激不尽...  
   
  程序要求实现  
   
   
                                  1  
                              1   2   1  
                          1   2   3   2   1  
                        .............  
   
  问题点数:20、回复次数:14Top

1 楼gxnet12(及郁闷)回复于 2005-05-29 19:53:26 得分 0

1  
                                  1   2   1  
                              1   2   3   2   1  
                        ...................  
  分不够再给...  
   
  在线等...Top

2 楼gxnet12(及郁闷)回复于 2005-05-29 19:54:17 得分 0

晕...最前面那一个1怎么不可以居中啊.  
   
  郁闷  
   
                          --------------------------------------------  
                                                                    1  
                                                                1   2   1  
                                                            1   2   3   2   1  
                                                    .......................Top

3 楼gxnet12(及郁闷)回复于 2005-05-29 20:22:10 得分 0

怎么没有人来回答我啊...  
   
  555Top

4 楼foochow(无聊,灌水......)回复于 2005-05-29 20:38:46 得分 2

用队列可以实现~~~-_-Top

5 楼gxnet12(及郁闷)回复于 2005-05-29 20:56:07 得分 0

楼上兄弟可以给出原程序吗.  
   
  谢谢...Top

6 楼mydefoliate()回复于 2005-05-29 21:21:26 得分 4

看看是不是这效果:  
   
  #include   <stdio.h>  
   
  void   main(   )  
  {  
  int   n,i,j;  
  scanf("%d",&n);  
  for(i=1;i<=n;i++){  
  for(j=0;j<n-i;j++)   printf("     ");  
  for(j=1;j<=i;j++)   printf("%d   ",j);  
  for(j=i-1;j>=1;j--)   printf("%d   ",j);  
  printf("\n");  
  }  
  }  
  Top

7 楼foochow(无聊,灌水......)回复于 2005-05-29 21:38:21 得分 4

#include<iostream>  
  #include<queue>  
  using   namespace   std;  
  int   main()  
  {  
  queue<int>Q;  
  Q.push(0);  
  Q.push(1);  
  Q.push(0);  
  int   s=0;  
  int   n;  
  cout<<"enter   n:";  
  cin>>n;  
  int   m=0;  
  for(int   i=1;i<=n;++i)  
  {  
  Q.push(0);  
  for(int   j=0;j<=2*i;++j)  
  {  
  int   t=Q.front();  
  Q.push(1+t);  
  Q.pop();  
  if(t)cout<<t<<"   ";  
  }  
  Q.push(0);  
  cout<<endl;  
  }  
  return   0;  
                    system("PAUSE");  
  }  
  Top

8 楼skyphantom()回复于 2005-05-29 21:38:55 得分 2

#pragma   warning(disable   :   4786)  
   
  #include<iostream>  
  #include   <string>  
  using   namespace   std;  
   
  void   main()  
  {  
  char   strTem[80];  
  string   strLast,   strLast_1,   strLast_2;  
  for(   int   i   =   1;   i   <   10;   i++)  
  {  
  itoa(   i,   strTem,   10);  
  strLast_1   =   strLast_1   +   "   "+   strTem;  
  if(i   >   1)  
  {  
  for(   int   j   =   i-1;   j   >=   1;   j--)  
  {  
  itoa(   j,   strTem,   10);  
  strLast_2=   strLast_2   +   "   "+   strTem;  
  }  
  }  
  strLast   =   strLast_1   +   "   "   +   strLast_2;  
  strLast_2   =   "";  
  cout   <<   strLast   <<   endl;  
  }  
  }Top

9 楼skyphantom()回复于 2005-05-29 21:43:46 得分 2

#pragma   warning(disable   :   4786)  
   
  #include<iostream>  
  #include   <string>  
  using   namespace   std;  
   
  void   main()  
  {  
  char   strTem[80];  
  string   strLast,   strLast_1,   strLast_2;  
  cout   <<   "Input   n"   <<   endl;  
  int   n   =   0;  
  cin   >>   n;  
  for(   int   i   =   1;   i   <=   n;   i++)  
  {  
  itoa(   i,   strTem,   10);  
  strLast_1   =   strLast_1   +   "   "+   strTem;  
  if(i   >   1)  
  {  
  for(   int   j   =   i-1;   j   >=   1;   j--)  
  {  
  itoa(   j,   strTem,   10);  
  strLast_2=   strLast_2   +   "   "+   strTem;  
  }  
  }  
  strLast   =   strLast_1   +   "   "   +   strLast_2;  
  strLast_2   =   "";  
  cout   <<   strLast   <<   endl;  
  }  
  }Top

10 楼gxnet12(及郁闷)回复于 2005-05-30 09:46:34 得分 0

TO:   mydefoliate()  
           
          你的只可以显示到1   2   1   后面的就出不来啦..而且像你这样的话如果我的数是无限大的话..那不是要写好久的代码....  
   
  TO:   foochow(恰似你的温柔)     skyphantom  
         
          你们两位的好像也不能实现我要的效果...  
             
          -----------------------------------------------------------------效果如下:  
                                                1  
                                                1   2   1  
                                                后面无法显示.  
                                                不管输入的值是多少!Top

11 楼QunKangLi(心里面疼得有点发酸 一定是有雾来了 打湿了我的眼眶)回复于 2005-05-30 11:41:55 得分 4

int   abs_int(   int   x   )  
  {  
  return   x   <   0   ?   -x   :   x   ;  
  }  
  void   print(   int   n   )    
  {  
  int   r,   c,   t,   h,   cc   ;  
  static   char   CH[]   =   "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"   ;  
  for(   cc   =   n+n-1,   h   =   cc/2,   r   =   0   ;   r   <   n   ;   ++r,   putchar('\n')   )  
  for(   c   =   0   ;   t   =   abs_int(c-h),   c   <   cc   ;   ++c   )  
  putchar(   r   <   t   ?   '   '   :   CH[r-t]   )   ;  
  }  
  int   main(   )  
  {  
  print(   40   )   ;  
  return   0   ;  
  }  
  Top

12 楼QunKangLi(心里面疼得有点发酸 一定是有雾来了 打湿了我的眼眶)回复于 2005-05-30 11:48:59 得分 2

数字版:  
  int   abs_int(   int   x   )  
  {  
  return   x   <   0   ?   -x   :   x   ;  
  }  
  void   print(   int   n   )    
  {  
  int   r,   c,   t,   h,   cc   ;  
  for(   cc   =   n+n-1,   h   =   cc/2,   r   =   0   ;   r   <   n   ;   ++r,   putchar('\n')   )  
  for(   c   =   0   ;   t   =   abs_int(c-h),   c   <   cc   ;   ++c   )  
  if(   r   <   t   )   printf(   "       "   )   ;  
  else   printf(   "%3d",   r-t+1   )   ;//格式符%xd中x为上一句中输出的空格数  
  }  
  int   main(   )  
  {  
  print(   10   )   ;  
  return   0   ;  
  }Top

13 楼gxnet12(及郁闷)回复于 2005-05-30 12:51:12 得分 0

楼上的没人加头文件吧  
  我加后好像是可以啦  
   
  但是不知道怎么停下来..  
  闪一下就过啦  
  也看不出到底是不是我要的效果..  
  Top

14 楼gxnet12(及郁闷)回复于 2005-05-30 13:09:24 得分 0

谢谢楼上的各位...根椐QunKangLi(To   iterate   is   human,to   recurse   divine)   数字版  
   
  我差不多调出来啦...  
   
  给我原程序  
  大家看看:  
  #include<iostream>  
  #include   <stdio.h>  
  int   abs_int(   int   x   )  
  {  
  return   x   <   0   ?   -x   :   x   ;  
  }  
  void   print(   int   n   )    
  {  
  int   r,   c,   t,   h,   cc   ;  
  for(   cc   =   n+n-1,   h   =   cc/2,   r   =   0   ;   r   <   n   ;   ++r,   putchar('\n')   )  
  for(   c   =   0   ;   t   =   abs_int(c-h),   c   <   cc   ;   ++c   )  
  if(   r   <   t   )   printf(   "       "   )   ;  
  else   printf(   "%3d",   r-t+1   )   ;//格式符%xd中x为上一句中输出的空格数  
  }  
  int   main(   )  
  {  
  print(   10   )   ;  
  getchar();  
  return   0   ;  
   
  }    
  Top

相关问题

  • 一个简单的程序!
  • 求一简单程序?
  • 一个简单的程序。。。
  • 求一段简单程序
  • 一个简单程序。
  • 一个简单的程序
  • 求助一简单程序
  • 一段简单COM程序的问题
  • 一个简单的程序!请做
  • 简单程序,帮忙看一下!

关键词

  • strlast
  • strtem
  • 程序
  • cout
  • push
  • using namespace std
  • include
  • void main

得分解答快速导航

  • 帖主:gxnet12
  • foochow
  • mydefoliate
  • foochow
  • skyphantom
  • skyphantom
  • QunKangLi
  • QunKangLi

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo