scanf :读取到空格或者换行的时候停止,不会读取换行回车符,换行回车还在输入缓冲区中。
getchar:读取一个字符(遇到换行或者回车不会停止,会读进去回车符)
getline:忽略前面的换行或者结束符合,读取到换行结束,可以读取空格,遇到火车停止,并且会把回车符号从内存中取出来丢弃。
gets():读入一个字符串,遇到空格不会停止,遇到回车停止,并且会把回车符号从内存中取出来丢弃。
使用实例如下:
#include <iostream>
#include <stack>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
stack<char> stk;
int n;
int i = 0;
int j = 0;
char s ;
scanf_s("%d",&n);
s=getchar();//读取回车符
for (i = 0; i < n; i++) {
while (!stk.empty()) {
stk.pop();
}
string str;
getline(cin, str);
//cout << str << endl;
//s= getchar();
//cout << s << endl;
for (j = 0; j < str.size(); j++) {
if (!stk.empty() && stk.top() == str[j]) {
stk.pop();
}
else{
stk.push(str[j]);
}
}
if (stk.empty()) {
printf("Yes");
}
else {
printf("No");
}
}
}