读数问题

来源:互联网 发布:矢量gif制作软件 编辑:程序博客网 时间:2024/04/27 20:01

/*读数问题*/
//110读作一百一十需4秒,101读作一百零一需4秒,100读作一百需2秒
#include<stdio.h>
#define max 10000
char number[max];
int time=0;
FILE *fpinput,*fpoutput;


int work(int a,int b)
{
         int m,n=b;
         for(m = a;m > 0;m--)
       {
       
   if(number[m]=='0')
     if(number[m-1]!='0')
                           n+=1;
          if(number[m] <= '9' && number[m] > '0')
             n+=2;
               }
   return n;
}

void main()
{
     int i,num;
  fpinput = fopen( "input.txt","r");
  fpoutput = fopen("output.txt","w");
  while(!(feof(fpinput)))
  {

  fscanf(fpinput,"%s",number);
  for(i=0;number[i]!='/0';i++);
  num=i;
  for(;number[i]=='0';i--);
  if(i!=num)
  {
   time=0;
   time=work(i,time);
  }
  else
         {
   time=1;
   time=work(i,time);
         }
  fprintf(fpoutput,"Result: %d /n",time);
  }
 fclose(fpinput);
 fclose(fpoutput);
}