Advertisement
Guest User

Test filename generator

a guest
Dec 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7.  
  8. char *filename(int len1, int len2) //returns name for the output file: res_<first sequence length>_<second sequence length>.csv
  9. {
  10.     char *ans = new char[16];
  11.     strcpy(ans, "res_");
  12.     vector<int> num;
  13.     while (len1 > 0)
  14.     {
  15.         num.push_back(len1%10);
  16.         len1 /= 10;
  17.     }
  18.     reverse(num.begin(), num.end());
  19.     for (int x: num)
  20.     {
  21.         char *s3 = new char;
  22.         *s3 = (char) ((int) '0' + x);
  23.         strcat(ans, s3);
  24.     }
  25.     strcat(ans, "_");
  26.     num.clear();
  27.     while (len2 > 0)
  28.     {
  29.         num.push_back(len2%10);
  30.         len2 /= 10;
  31.     }
  32.     reverse(num.begin(), num.end());
  33.     for (int x: num)
  34.     {
  35.         char *s3 = new char;
  36.         *s3 = (char) ((int) '0' + x);
  37.         strcat(ans, s3);
  38.     }
  39.     strcat(ans, ".csv");
  40.     return ans;
  41. }
  42.  
  43. int main()
  44. {
  45.     for (int i = 1; i < 5; i++)
  46.         for (int j = 1; j < 7; j++)
  47.             cout << filename(i, j) << "\n";
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement