Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. aaaaaaa
  2. aaaaaab
  3. aaaaaac
  4. .
  5. .
  6. .
  7. zzzzzzx
  8. zzzzzzy
  9. zzzzzzz
  10.  
  11.  
  12.  
  13. for(i = 0; i<length; i++){
  14. pass[i] = 'a';
  15. }
  16.  
  17. while(1){
  18. for(j=0;j<26;j++){
  19. printf("%sn",pass);
  20. pass[i] = (char)(pass[i]+1);
  21. }
  22. if(pass[i-1]==z)...
  23. }
  24. return 0;
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. void iterate(char *str, int idx, int len) {
  30. char c;
  31.  
  32. if (idx < (len - 1)) {
  33. for (c = 'a'; c <= 'z'; ++c) {
  34. str[idx] = c;
  35.  
  36. iterate(str, idx + 1, len);
  37. }
  38. } else {
  39. for (c = 'a'; c <= 'z'; ++c) {
  40. str[idx] = c;
  41.  
  42. printf("%sn", str);
  43. }
  44. }
  45. }
  46.  
  47. #define LEN 3
  48.  
  49. int main(int argc, char **argv) {
  50. char str[LEN + 1];
  51.  
  52. memset(str, 0, LEN + 1);
  53.  
  54. iterate(str, 0, LEN);
  55. }
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60.  
  61. int isFinish(char *str){
  62. return ''== str[strspn(str, "z")];
  63. }
  64.  
  65. void inc_str(char *str){
  66. int index, carry;
  67. for(index = strlen(str)-1;index>=0;--index){
  68. if(str[index] == 'z'){
  69. carry = 1;
  70. str[index] = 'a';
  71. } else {
  72. carry = 0;
  73. str[index] += 1;
  74. }
  75. if(carry == 0)break;
  76. }
  77. }
  78.  
  79. int main(){
  80. int n;
  81. char *str;
  82.  
  83. n=7;//length
  84. str=(char*)malloc(sizeof(char)*(n+1));
  85. //initialize
  86. memset(str, 'a', n);//"aa..aa"
  87. str[n]='';
  88.  
  89. while(1){
  90. printf("%sn", str);
  91. if(isFinish(str))
  92. break;
  93. inc_str(str);
  94. }
  95. free(str);
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement