刘汝佳算法入门之第二章之习题之一

#define LOCAL

#include<stdio.h>

#include<math.h>

int main()

{

#ifdef LOCAL

freopen("E:\\c\\input1.txt","r",stdin);

freopen("E:\\c\\output1.txt","w",stdout);

#endif

int x0,x,i,n=0,count=1;

while(scanf("%d",&x)==1)

{

x0=x;

for(i=8;i>0;i--)

{

x%=(int)(pow(10,i));if(x0!=x) count++;//count初值应该为1,因为个位最后会相等 

}

        printf("%d\n",count);

        return 0;

}

}

FOPEN版

#include<stdio.h>

#include<math.h>

int main()

{

/*#ifdef LOCAL

freopen("E:\\c\\input1.txt","r",stdin);

freopen("E:\\c\\output1.txt","w",stdout);

#endif */

FILE *fin,*fout;

fin=fopen("E:\\c\\input1.txt","rb");

fout=fopen("E:\\c\\output.txt","wb");

int x0,x,i,n=0,count=1;

while(fscanf(fin,"%d",&x)==1)

{

x0=x;

for(i=8;i>0;i--)

{

x%=(int)(pow(10,i));if(x0!=x) count++;//count初值应该为1,因为个位最后会相等 

}

        fprintf(fout,"%d\n",count);

        fclose(fin);

        fclose(fout);

        return 0;

}

}

posted on 2011-10-10 23:50  csushin  阅读(149)  评论(0)    收藏  举报