バイトジャンプ2019校招第3回筆記試験問題解
1、最長重複しないサブストリング
2、組織最適化(マトリックス連通領域の個数を求める)
3、IP還元
4、UTF-8検査
5、トリル人気者
ある頂点からの到達頂点数を求める問題があり、書く時間がないような気がします.cout<<1<
#include
#include
using namespace std;
int solve(const string &str){
int hash[256]={0};
int start=0;
int mstart=0;
int mlen=0;
int idx=0;
int len=0;
while(idx!=str.size()){
if(hash[str[idx]]==1){
if(len>mlen){
mstart=start;
mlen=len;
}
while(str[start]!=str[idx]){
hash[str[start]]=0;
start++;
len--;
}
start++;
}
else{
hash[str[idx]]=1;
len++;
}
idx++;
}
if(len>mlen){
mlen=len;
mstart=start;
}
return mlen;
}
int main()
{
string str;
while(cin>>str){
cout<
2、組織最適化(マトリックス連通領域の個数を求める)
#include
#include
using namespace std;
#define size 500
int I[size][size];
int n=0,mmin,mmax;
int num = 0;
bool check(int x, int y){
if (x >= 0 && x <= n && y >= 0 && y <= n && I[x][y] != 0)
{
return true;
}else
{
return false;
}
}
int main(void)
{
while(cin>>n){
for (int i = 0; i < n; ++i)
{
for (int j=0; j< n; j++)
{
cin>>I[i][j];
}
}
int label = 1;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (check(i, j))
{
if (check(i, j-1))
{
if (check(i-1, j))
{
mmin = I[i-1][j];
mmax = I[i][j-1];
if (mmax < mmin) {
mmin = I[i][j-1];
mmax = I[i-1][j];
for (int t = j; t >= 0; t--)
{
for (int w = i; w >=0; w--)
{
if (I[w][t] == mmax) { I[w][t] = mmin; }
}
}
label--;
}
I[i][j] = mmin;
} else
{
I[i][j] = I[i][j-1];
}
} else if (check(i-1, j))
{
I[i][j] = I[i-1][j];
} else
{
label ++;
I[i][j] = label;
}
}
}
}
num = label - 1;
cout<
3、IP還元
#include
#include
#include
using namespace std;
void msolve(string s, int n, string out, int& res) {//out IP
if (n == 4) {
if (s.empty()) {//out IP
++res;
//cout< 255 || k != to_string(val).size()) continue;
msolve(s.substr(k), n + 1, out + s.substr(0, k) + (n == 3 ? "" : "."), res);
}
}
}
int solve(string s) {
int res=0;
msolve(s, 0, "", res);
return res;
}
int main()
{
string str;
while(cin>>str){
cout<
4、UTF-8検査
#include
#include
#include
using namespace std;
bool isOneByte(char i)
{
return (i & 0x80) == 0;
}
bool isDataByte(char i)
{
return (i & 0xC0) == 0x80;
}
int getDataCount(char i)
{
int bit = 7;
int count = 0;
while(bit >= 0 && ((1 << bit) & i))
{
++count;
--bit;
}
return count;
}
bool solve(vector& data) {
int k = 0;
int count = 0;
while(k < data.size())
{
char real = data[k] & 0xFF;
if(isOneByte(real))
{
if(count != 0)
{
return false;
}
}
else
{
if(isDataByte(real))
{
if(count <= 0)
{
return false;
}
else
{
--count;
}
}
else
{
if(count != 0)
{
return false;
}
else
{
count = getDataCount(real) - 1;
}
}
}
++k;
}
return count == 0;
}
int main()
{
int n;
while(cin>>n){
vector v(n);
for(auto i=0;i>v[i];
}
cout<
5、トリル人気者
ある頂点からの到達頂点数を求める問題があり、書く時間がないような気がします.cout<<1<