警示后人和自己

P4414 [COCI2006-2007#2] ABC

juice88 @ 2024-03-02 12:52:51

在做这道题的过程中,我的思路是使用

    for (int i = 0; i < 3; i++) 
        scanf("%c", &q[i]);

但在实际运行时,这个循环只能识别到前两个字符,后面我才发现这个循环会把前面的换行符也当作字符。那么在使用scanf读取字符时,应该在格式字符串中加上空格,例如scanf(" %c", &q[i]);,这样可以忽略输入字符前面的空格和换行符。

    for (int i = 0; i < 3; i++) {
        scanf(" %c", &q[i]);

by shan233 @ 2024-03-02 13:34:55

帮大忙了,谢谢!


by baisedeyun @ 2024-03-31 09:46:23

为什么换行符可以用空格啊


by Windy0430 @ 2024-04-21 17:54:15

题解来喽```cpp

include <bits/stdc++.h>

using namespace std; int a , b , c , a1 , b1 , c1 , d; char A , B , C; int main(){ cin >> a >> b >> c ; if (a > b){ d = b; b = a; a = d; } if (b > c){ d = c; c = b; b = d; } if (a > b){ d = b; b = a; a = d; } cin >> A >> B >> C; if (A == 'A'){ cout << a << " "; } if (A == 'B'){ cout << b << " "; } if (A == 'C'){ cout << c << " "; } if (B == 'A'){ cout << a << " "; } if (B == 'B'){ cout << b << " "; } if (B == 'C'){ cout << c << " "; } if (C == 'A'){ cout << a << " "; } if (C == 'B'){ cout << b << " "; } if (C == 'C'){ cout << c << " "; } return 0; }


|