-
Notifications
You must be signed in to change notification settings - Fork 7
/
152.cpp
54 lines (43 loc) · 824 Bytes
/
152.cpp
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
48
49
50
51
52
// C++ program to divide a string
// in n equal parts
#include<iostream>
#include<string.h>
using namespace std;
class gfg
{
// Function to print n equal parts of str
public:
void divideString(char str[], int n)
{
int str_size = strlen(str);
int i;
int part_size;
// Check if string can be divided in
// n equal parts
if (str_size % n != 0)
{
cout<<"Invalid Input: String size";
cout<<" is not divisible by n";
return;
}
// Calculate the size of parts to
// find the division points
part_size = str_size / n;
for (i = 0; i< str_size; i++)
{
if (i % part_size == 0)
cout<<endl;
cout<< str[i];
}
}
};
// Driver code
int main()
{
gfg g;
// length od string is 28
char str[] = "a_simple_divide_string_quest";
// Print 4 equal parts of the string
g.divideString(str, 4);
return 0;
}