正文

successive numeral 2008-03-23 13:34:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/zhaoyg/33529.html

分享到:

/*output a successive numeral both sides the character '-' from lift to rightexample :input : 1,4,3-9,3,7-9#1,3d-5# output: 1,4,3,4,5,6,7,8,9,3,7,8,9illegal zhaoyg 2008.1.11*/ #include <stdio.h>#include <conio.h> int main(){ int flage=0,input,input_end,temp; int in[100][2]={0} , count=-1;  printf("add '#' as a end of input , and a sigle '#' to end\n");  int a=0;  while( (flage=scanf("%d",&input))==1 && input!='#') {   in[++count][0]=input;   if ((temp=getchar())!=',' && temp!='-')  {   flage=0;   break;  }   if (temp=='-')   {   if(scanf("%d",&input_end)==1)   {    in[count][1]=input_end;     if ((temp=getchar())!=',' && temp!='#')// eat off ',' after intput_end    {     flage=0;     break;    }     if (temp=='#')     break;   }   else    {    flage=0;    break;   }  } }  if ( flage != EOF && flage==0 )  printf("illegal\n"); else {  for (int i=0; i<=count  ; i++)  {   printf("%d,",in[i][0]);    if ( in[i][1]!=0)   {    for (temp=in[i][0]+1;temp<=in[i][1];temp++)     printf("%d,",temp);   }  } }  getch(); return 0;}

阅读(1942) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册