HDU 6208
关闭同步之后cin得到加速
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
string st[qq];
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
int t; cin >> t;
while(t--) {
int n; cin >> n;
int id, maxn = 0;
bool f = true;
for(int i = 1; i <= n; ++i) {
cin >> st[i];
int len = st[i].size();
if(len > maxn) {
maxn = len, id = i;
}
}
for(int i = 1; i <= n; ++i) {
if(i == id) continue;
if(st[id].find(st[i]) == string::npos) {
f = false;
break;
}
}
if(!f) cout << "No" << endl;
else cout << st[id] << endl;
}
return 0;
}
本文介绍了在C++编程中如何使用cin.tie(0)和ios::sync_with_stdio(0)来关闭输入输出同步,从而提升cin读取速度。以HDU 6208题目为例,展示了关闭同步后cin读入的效率提升。
917

被折叠的 条评论
为什么被折叠?



