寻找序列
寻找序列
AcWing3730
https://www.acwing.com/problem/content/3733/
构造题 二维数组存数据
注意最后一个元素n,既要满足和首位元素不同还要和n-1位不同。
代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int n;
int a[4][N];
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i <= 3; i ++ )
for (int j = 1; j <= n; j ++ )
cin >> a[i][j];
a[4][1] = a[1][1];
for (int j = 1; j < n; j ++ )
for (int i = 1; i <= 3; i ++ )
if (a[4][j] != a[i][j+1])
{
a[4][j+1] = a[i][j+1];
break;
}
for (int i = 1; i <= 3; i ++ )
{
if (a[i][n] != a[4][1] && a[i][n] != a[4][n-1])
{
a[4][n] = a[i][n];
break;
}
}
for (int i = 1; i <= n; i ++ ) cout << a[4][i] << ' '; cout << endl;
}
return 0;
}