problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
comp526::snowflakes 命名空间参考

函数

int main (istream &cin, ostream &cout)
 
 TEST (snowflakes, case1)
 

函数说明

◆ main()

int comp526::snowflakes::main ( istream & cin,
ostream & cout )

在文件 comp526.cpp231 行定义.

231 {
232 int testCases;
233 cin >> testCases;
234 while(testCases--) {
235 int n;
236 cin >> n;
237 if(n == 0) {
238 cout << 0 << endl;
239 break;
240 }
241 vector<int> snowflakes(n);
242 for(int i = 0; i < n; ++i) {
243 cin >> snowflakes[i];
244 }
245 unordered_map<int, int> lastSeen;
246 int left = 0;
247 int maxLength = 0;
248 for(int right = 0; right < n; ++right) {
249 int currentSnowflake = snowflakes[right];
250 if(lastSeen.count(currentSnowflake)) {
251 left = max(left, lastSeen[currentSnowflake] + 1);
252 }
253 lastSeen[currentSnowflake] = right;
254 maxLength = max(maxLength, right - left + 1);
255 }
256 cout << maxLength;
257 }
258
259 return 0;
260 }

被这些函数引用 TEST().

◆ TEST()

comp526::snowflakes::TEST ( snowflakes ,
case1  )

在文件 comp526_test.cpp172 行定义.

172 {
173 istringstream in("1\n5\n1\n2\n3\n2\n1\n");
174 auto out = ostringstream();
175 main(in, out);
176 const auto ans = out.str();
177 ASSERT_EQ("3", ans);
178 }
int main(istream &cin, ostream &cout)

引用了 main().