为什么用cin.get();会全部WA?

P3367 【模板】并查集

@[JustinQLZ](/space/show?uid=44099) 你用get(str,cin);试试???
by 氷スイカ233 @ 2018-07-12 10:48:48


@[Ice_watermelon233](/space/show?uid=97934) 可是我只是想读入z,不需要读入一整行啊。。(而且那样会更慢吧ORZ)
by JustinQLZ @ 2018-07-12 10:56:06


@[JustinQLZ](/space/show?uid=44099) 那我就不懂了233
by 氷スイカ233 @ 2018-07-12 11:05:03


@[JustinQLZ](/space/show?uid=44099) ```cpp for (int i = 1; i <= m; ++i) { cin.get(); <----这一行干什么用 if (cin.get() == '1') { ```
by andyli @ 2018-07-12 11:44:34


@[JustinQLZ](/space/show?uid=44099) 建议你输入数字1
by andyli @ 2018-07-12 11:45:54


@[Ice_watermelon233](/space/show?uid=97934) $ \text{你看看我代码:} $ ```cpp #include <iostream> using namespace std; const int maxn = 200050; int p[maxn], cnt; int find(int x) { return p[x] == x ? x : (p[x] = find(p[x])); } void hb(int x, int y) { int u = find(p[x]), v = find(p[y]); if (u != v) { cnt--; p[u] = v; } } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) p[i] = i; cnt = n; while (m--) { int a, b, c; cin >> a >> b >> c; if (a == 1) hb(b, c); else if (find(b) == find(c)) cout << "Y" << endl; else cout << "N" << endl; } return 0; } ```
by andyli @ 2018-07-12 11:46:47


@[andyli](/space/show?uid=84282) Orz总算看懂了qwq
by 氷スイカ233 @ 2018-07-12 11:48:15


另外cnt不需要(我的代码中有)
by andyli @ 2018-07-12 11:50:08


@[andyli](/space/show?uid=84282) 其实我用```cin >> ch```已经过了23333搜了一下,大概是因为Wnidows下换行是\r\n,Linux下换行是\n?
by JustinQLZ @ 2018-07-20 11:37:35


@[JustinQLZ](/space/show?uid=44099) cin >> ch 会跳过空白(包括`\r`, `\n`, `\t`等)
by andyli @ 2018-07-20 12:27:30


|