fork(1) download
  1. #include<bits/stdc++.h>
  2. using q=std::string;using z=std::vector<q>;z operator/(q s,int d){int p=s.length()/d,i=0;z a;for(;i<d+1;){a.push_back(s.substr(i++*p,i^d?p:-1));}return a;}
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. ostream& operator<<(ostream& out, const vector<string> &e){
  7. out << "([";
  8. for(int i=0;i<e.size()-1;i++){
  9. if(i){
  10. out << ", ";
  11. }
  12. cout << '"' << e[i] << '"';
  13. }
  14. out << "], ";
  15. out << '"' << e.back() << '"' << ")";
  16. return out;
  17. }
  18. int main() {
  19. vector<string> testStr = {"Hello, world!", "Hello, world!", "ABCDEFGH", "123456789", "ALABAMA", "1234567"};
  20. vector<int> testNum = {4,5,2,5,3,4};
  21. for(int i=0;i<testStr.size();i++){
  22. cout << testStr[i] << " / " << testNum[i] << " = " << testStr[i]/testNum[i] << endl;
  23. }
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 16056KB
stdin
Standard input is empty
stdout
Hello, world! / 4 = (["Hel", "lo,", " wo", "rld"], "!")
Hello, world! / 5 = (["He", "ll", "o,", " w", "or"], "ld!")
ABCDEFGH / 2 = (["ABCD", "EFGH"], "")
123456789 / 5 = (["1", "2", "3", "4", "5"], "6789")
ALABAMA / 3 = (["AL", "AB", "AM"], "A")
1234567 / 4 = (["1", "2", "3", "4"], "567")