New task (a bit simpler). Optimized synchronous socket

This commit is contained in:
ftc
2023-03-02 22:23:00 +03:00
parent f111eb085d
commit 9e15e07d6f
2 changed files with 7 additions and 12 deletions
+6 -11
View File
@@ -4,20 +4,15 @@
using namespace std;
int cnt[256];
string Task(const string &message)
{
memset(cnt, 0, sizeof(cnt));
string result = "";
int result_length = message.length() / 8;
if (result_length < 1) result_length = 1;
for (int i = 0; i < result_length; i++) result += '\x0';
for (int i = 0; i < (int)message.length(); i++)
{
cnt[(int)(unsigned char)message[i]]++;
result[i % result_length] ^= message[i];
}
ostringstream result;
for (int i = 0; i < 256; i++)
{
if (cnt[i] == 0) continue;
result << i << ":" << cnt[i] << ";";
}
return result.str();
return result;
}