Acwing每日一题:寻找序列(模拟题)
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int a[4][N];
int n;
int main()
{
int T;
scanf("%d", &T);
while (T -- )
{
cin >> n;
for (int i = 0; i < 3; i ++ )
for (int j = 1; j <= n; j ++ )
scanf("%d", &a[i][j]);
for (int j = 1; j < n; j ++ )
for (int i = 0; i < 3; i ++ )
{
a[3][j] = a[i][j];
if(a[3][j] != a[3][j - 1])
{
break;
}
}
for (int i = 0; i < 3; i ++ )
{
a[3][n] = a[i][n];
if(a[3][n] != a[3][n - 1] && a[3][n] != a[3][1]) break;
}
for (int i = 1; i <= n; i ++ ) printf("%d ", a[3][i]);
cout << endl;
}
return 0;
}
Leetcode每日一题:Excel表列名称
原题链接
一般情况下的进制转换都是取模然后整除,这道题因为没有0,所以每个十进制的数需要先-1
class Solution {
public:
string convertToTitle(int n) {
string res;
while (n --)
{
res = char(n % 26 + 'A') + res;
n /= 26;
}
return res;
}
};
本文解析了AcWing的寻找序列模拟题,通过C++实现,并介绍了LeetCode上的Excel表列名称题目的解决方案,利用进制转换思路进行编程实现。
730

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



