poj 2105

#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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值