字节2019年春招的第一题
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n, i, j, si = 0,c=0, k = 0;
char a[100], b[100][100];
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a;
si = strlen(a);
for (j = 0; j < si; )
{
if (a[j] == '\0')
{
break;
}
if ((a[j] == a[j + 1]) && (a[j] == a[j + 2]))
{
for (c = j; c < si; c++)
{
a[c] = a[c + 1];
if (a[c] == '\0')
{
break;
}
}
cout << a[si];
continue;
}
if ((a[j] == a[j + 1]) && (a[j + 2] == a[j + 3]) && (a[j + 4] == a[j + 5]))
{
for (c = j + 2; c < si; c++)
{
a[c] = a[c + 1];
if (a[c] == '\0')
{
break;
}
}
continue;
}
if ((a[j] == a[j + 1]) && (a[j + 2] == a[j + 3]))
{
for (c = j + 2; c < si; c++)
{
a[c] = a[c + 1];
if (a[c] == '\0')
{
break;
}
}
continue;
}
j++;
}
while (1)
{
b[i][k] = a[k];
if (a[k] == '\0')
{
break;
}
k++;
}
k = 0;
}
for (i = 0; i < n; i++)
{
while (b[i][k] != '\0')
{
cout << b[i][k];
k++;
}
k = 0;
if (i == n - 1)
{
continue;
}
cout <<'\n' ;
}
}
全部评论
(0) 回帖