| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:呵呵,还好,知道错了,高手能不能讲讲,getchar,和 scanf(%c) 的效果有什么不同?为什么改用 scanf(%c)就能过了In Reply To:呵呵,还好,知道错了,高手能不能讲讲,getchar,和 scanf(%c) 的效果有什么不同?为什么改用 scanf(%c)就能过了 Posted by:sunmoonstar_love at 2005-06-12 00:16:32 #include"iostream"
#include"math.h"
using namespace std;
int main()
{
char str[32];
int i=0,j=0,n,sum,k;
scanf("%d",&n);
for( k=0;k<n;k++)
{
sum=0;
scanf("%s",str);
for(i=0;i<32;i++)
{
if(0<=i&&i<8&&str[i]!='0')
sum+=pow(2,7-i);
else if(8<=i&&i<16&&str[i]!='0')
sum+=pow(2,15-i);
else if(16<=i&&i<24&&str[i]!='0')
sum+=pow(2,23-i);
else if(24<=i&&i<32&&str[i]!='0')
sum+=pow(2,31-i);
j++;
if(j%8==0)
{
printf("%d",sum);
sum=0;
if(i<24)
printf(".");
else
printf("\n");
}
}
}
return 0;
}
这个程序是AC了的,但用gets(str)代scanf("%s",str);程序就会有问题。。。。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator