-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.c
More file actions
47 lines (39 loc) · 773 Bytes
/
encryption.c
File metadata and controls
47 lines (39 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// https://www.hackerrank.com/challenges/encryption/problem
#include <stdio.h>
#include <string.h>
#include <math.h>
int main (void)
{
char str[82];
scanf("%s",str);
int length = strlen(str);
int row = pow(length,0.5);
float col = pow(length,0.5);
if (col - (int)col != 0)
{
col = row + 1;
}
if (col * row < length)
{
row = col;
}
int i,j;
for (i = 0; i < col;i++)
{
for (j = 0; j < row; j++)
{
int pos = i + j * col;
if (pos < length)
{
printf("%c",str[pos]);
}
else
{
break;
}
}
printf(" ");
}
printf("\n");
return 0;
}