随机生成 排序数组 我们将随机数组元素存储在一个数组中,然后对其进行排序并打印。
null
// A C++ Program to generate test cases for // array filled with random numbers #include<bits/stdc++.h> using namespace std; // Define the number of runs for the test data // generated #define RUN 5 // Define the range of the test data generated #define MAX 100000 // Define the maximum number of array elements #define MAXNUM 100 int main() { // Uncomment the below line to store // the test data in a file // freopen("Test_Cases_Random_Sorted_Array.in", // "w", stdout); // For random values every time srand ( time (NULL)); int NUM; // Number of array elements for ( int i=1; i<=RUN; i++) { int arr[MAXNUM]; NUM = 1 + rand () % MAXNUM; // First print the number of array elements printf ( "%d" , NUM); // Then print the array elements separated by // space for ( int j=0; j<NUM; j++) arr[j] = rand () % MAX; // Sort the generated random array sort (arr, arr + NUM); // Print the sorted random array for ( int j=0; j<NUM; j++) printf ( "%d " , arr[j]); printf ( "" ); } // Uncomment the below line to store // the test data in a file // fclose(stdout); return (0); } |
随机生成 回文
- 测试用例生成计划生成奇数和偶数长度的回文。
- 测试用例生成计划使用了最不受重视的数据结构之一- 德克
- 因为回文从左到右都是一样的,所以我们只需在左边和右边都放上相同的随机字符(使用 向前推 )右侧(使用 推回( ))
// A C++ Program to generate test cases for // random strings #include<bits/stdc++.h> using namespace std; // Define the number of runs for the test data // generated #define RUN 5 // Define the range of the test data generated // Here it is 'a' to 'z' #define MAX 25 // Define the maximum length of string #define MAXLEN 50 int main() { // Uncomment the below line to store // the test data in a file // freopen("Test_Cases_Palindrome.in", "w", // stdout); // For random values every time srand ( time (NULL)); // A container for storing the palindromes deque< char > container; deque< char >::iterator it; int LEN; // Length of string for ( int i=1; i<=RUN; i++) { LEN = 1 + rand () % MAXLEN; // First print the length of string printf ( "%d" , LEN); // If it is an odd-length palindrome if (LEN % 2) container.push_back( 'a' + rand () % MAX); // Then print the characters of the palindromic // string for ( int j=1; j<=LEN/2; j++) { char ch = 'a' + rand () % MAX; container.push_back(ch); container.push_front(ch); } for (it=container.begin(); it!=container.end(); ++it) printf ( "%c" ,*it); container.clear(); printf ( "" ); } // Uncomment the below line to store // the test data in a file // fclose(stdout); return (0); } |
本文由 拉希特·贝尔瓦里亚 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
参考资料: http://spojtoolkit.com/TestCaseGenerator/
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END