题目数据输入中间读入字符

http://acm.hnust.edu.cn/JudgeOnline/problem.php?cid=1310&pid=1

科大oj上这道题在输入中间读入字符,开始用字符都怎么都不对,看了老师的程序发现用的是字符串。。。

顺便附下代码:

   

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
#define inf 1e-4
using namespace std;
const int maxn = 1005;
int f[maxn];
int x[maxn], y[maxn], op[maxn];
int n, d;

int find(int x)
{
    return f[x] == x ? x : f[x] = find(f[x]);
}

void Union(int x, int y)
{
    int rx = find(x);
    int ry = find(y);
    if (rx != ry)
        f[rx] = ry;
}

int main()
{
    while (scanf("%d%d", &n, &d) == 2)
    {
        memset(op, 0, sizeof(op));
        for (int i = 1; i <= n; i++) {
            f[i] = i;
            scanf("%d%d", &x[i], &y[i]);
        }
        char c[5];
        int p, q;
        while (scanf("%s",&c)==1)//字符串!!!
        {
            if (strcmp(c,"O")==0) {//字符串!!!
                scanf("%d", &p);
                op[p] = 1;
                for (int i = 1; i <= n; i++) {
                    if (op[i]) {
                        double dd = sqrt((double)(x[i] - x[p])*(double)(x[i] - x[p]) + (double)(y[i] - y[p])*(double)(y[i] - y[p]));
                        if (dd<=d)//直接这样比较,之前用精度比较好像总是WA
                            Union(i, p);
                    }
                }
            }
            else
            {
                scanf("%d%d", &p, &q);
                if (find(p) == find(q))
                    printf("SUCCESS
");
                else    
                    printf("FAIL
");
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zxhyxiao/p/6916669.html