poj 1654 Area

poj 1654 Area,第1张

poj 1654 Area
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;int main(){    int t;    scanf("%d", &t);    getchar();    while (t--)    {        long long ans = 0;        int x = 0;        int y = 0;        char ch;        while (ch = getchar(), ch != '5')        { switch (ch) { case '1':     ans -= y * 2 - 1;     x--;     y--;     break; case '2':     y--;     break; case '3':     ans += y * 2 - 1;     x++;     y--;     break; case '4':     ans -= y * 2;     x--;     break; case '6':     ans += y * 2;     x++;     break; case '7':     ans -= y * 2 + 1;     x--;     y++;     break; case '8':     y++;     break; case '9':     ans += y * 2 + 1;     x++;     y++;     break; }        }        getchar();        if (ans < 0) ans = -ans;        if (ans & 1) cout << ans / 2 << ".5" << endl;        else cout << ans / 2 << endl;    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4931920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存