Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why wa again and again on 2105? 大大们 help!

Posted by dxcug at 2004-12-05 21:28:44 on Problem 2105
here is my code and it passes the sample very well:
#include<stdio.h>
#include<stdlib.h>

void trans(char *bits,int *bytes)
{
	int i,j;
	for(i=0;i<4;i++)
	{
		bytes[i]=0;
		for(j=0;j<8;j++)
			bytes[i]+=(bits[i*8+j]&1)<<(7-j);
	}
}

int main()
{
	char bit[32];
	int ip[4];
	int n,i,j;
	while(scanf("%d",&n)!=EOF){
		getchar();
		for(i=0;i<n;i++){
			for(j=0;j<32;j++)
				scanf("%c",&bit[j]);
			getchar();
			trans(bit,ip);
			for(j=0;j<4;j++){
				if(j==0)
					printf("%d",ip[j]);
				else 
					printf(".%d",ip[j]);
			}
			printf("\n");
		}
	}
	return 1;
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator