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

后来的请注意EOF!附代码

Posted by croath at 2010-08-02 10:48:29 on Problem 2105
#include "stdio.h"
#include "math.h"
int num[33], add[5];
int ten(int a, int b);
int main() {
	int n, i;
	char temp;
	scanf("%d", &n);
	while (1) {
		temp = getchar();
		if (temp == '\n')
			break;
	}
	while (n--) {
		i = 0;
		while (1) {
			temp = getchar();
			if (i < 32 && (temp == '1' || temp == '0')) {
				i++;
				num[i] = temp - '0';
			}
			else if (temp == '\n')//这样就错了,加上 || temp == EOF就对了!晕死
				break;
		}
		for (i = 1; i <= 4; i++) {
			add[i] = ten(8 * (i - 1) + 1, 8 * i);
		}
		printf("%d.%d.%d.%d\n", add[1], add[2], add[3], add[4]);
	}
	return 0;
}

int ten(int a, int b) {
	int i, ip = 0;
	for (i = a; i < b; i++) {
		ip += num[i] * pow(2, 8 - i % 8);
	}
	ip += num[b];
	return ip;
}

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