poj 2105

来源:互联网 发布:mac谷歌浏览器安装 编辑:程序博客网 时间:2024/04/26 05:11
#include<stdio.h>#include<string.h>#include<math.h>int main(){    int i,j,N,sum=0;    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    char str[35];    scanf("%d",&N);    for(i=0; i<N; i++)    {        sum=0;        scanf("%s",str);        for(j=0; j<8; j++)        {            sum+=pow(2,7-j)*(str[j]-'0');        }        printf("%d.",sum);        sum=0;        for(j=8; j<16; j++)        {            sum+=pow(2,15-j)*(str[j]-'0');        }        printf("%d.",sum);        sum=0;        for(j=16; j<24; j++)        {            sum+=pow(2,23-j)*(str[j]-'0');        }        printf("%d.",sum);        sum=0;        for(j=24; j<32; j++)        {            sum+=pow(2,31-j)*(str[j]-'0');        }        printf("%d\n",sum);    }    //fclose(stdin);    //fclose(stdout);    return 0;}

 

直接在文件中输入与输出

freopen("in.txt","r",stdin);

freopen("out.txt","w",stdout);

fclose(stdin);

fclose(stdout);

 

函数名:freopen
 
函数,以指定模式重新指定到另一个文件。模式用于指定新文件的访问方式。
头文件:stdio.h
 
C89函数声明:
FILE *freopen( const char *filename, const char *mode, FILE *stream );
C99函数声明:
FILE *freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream);
 
形参说明:
filename:需要重定向到的文件名或文件路径。
mode:代表文件访问权限的字符串。例如,"r"表示“只读访问”、"w"表示“只写访问”、"a"表示“追加写入”。
stream:需要被重定向的文件流。
返回值:如果成功,则返回该指向该输出流的文件指针,否则返回为NULL。

 

0 0
原创粉丝点击