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

怎么这个题也出现C++AC G++WA的囧事?

Posted by Dumbear at 2009-02-12 02:55:34 on Problem 1654
#include <cstdio>
#include <cmath>

using namespace std;

const int d[][2] = {{0, 0}, {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
long long ans;

int main() {
    int t;
    char ch;
    scanf("%d", &t);
    for (int i = 0, x, y; i < t; ++i) {
        ans = x = y = 0;
        for (scanf("%c", &ch); ch != '5'; scanf("%c", &ch)) {
            if (ch < '1' || ch > '9')
                continue;
            int _x = x, _y = y;
            ans += (x += d[ch - '0'][0]) * _y - _x * (y += d[ch - '0'][1]);
        }
        if (ans < 0)
            ans = -ans;
        if (ans % 2 == 0)
            printf("%lld\n", ans / 2);
        else
            printf("%lld.5\n", ans / 2);
    }
    return 0;
}

rt,这个代码有问题么?

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