Главная страница


ru.algorithms

 
 - RU.ALGORITHMS ----------------------------------------------------------------
 From : Dmitriy Gerasimenko                  2:5020/400     23 Jul 2002  14:51:12
 To : Alexander Hritonenkov
 Subject : Re: Пеpебоp чисел
 -------------------------------------------------------------------------------- 
 
 
 >  DG> Резyльтат вывода для числа:
 >  DG> [1234]
 >
 >  DG> 1 : 2134
 >  DG> 2 : 2314
 >  DG> 3 : 2341
 >  DG> 4 : 3241
 >  DG> 5 : 3421
 >  DG> 6 : 3412
 >  DG> 7 : 4312
 >  DG> 8 : 4132
 >  DG> 9 : 4123
 >  DG> 10 : 1423
 >  DG> 11 : 1243
 >  DG> 12 : 1234
 
 AH> А где же вот это?
 AH> 2143
 AH> 3214
 AH> 4321
 AH> 1432
 AH> 1324
 AH> 1342
 AH> 2413
 AH> 2431
 AH> 3124
 AH> 3142
 AH> 4213
 AH> 4231
 AH> Или это yже не пеpестановки?
 
 Я знаю что она выводит не всё. Она была показана для сравнения.
 А программу пусть доделывают те кому это интересно или (и) надо,
 а правильная программа (один из её вариантов), если угодно,
 находится ниже, (кстати она уже печаталась ранее, сдесь же.)
 
 #include <dir.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <conio.h>
 #include <process.h>
 #include <string.h>
 #include <ctype.h>
 
 enum TOperator {PRINT, NEXT_SYMBOL, NEXT_POSITION};
 char *sOperation[]= {"PRINT", "NEXT_SYMBOL", "NEXT_POSITION"};
 
 int main(int c, char **argv)
 {
   char *bytes;
   char *pbytes;
   char *pargv;
   char *trigger;
   char filename[MAXPATH];
   TOperator op;
   int position;
   int count_position;
   FILE *stream;
   unsigned long count;
   //--------------------------------------------------------------
   if (c <= 1) {
     fprintf(stderr, "\nBad command line argument.");
     exit(1);
   }
   //--------------------------------------------------------------
   if (c == 3) {
     count_position= atoi(argv[2]);
     if (count_position == 0) {
         fprintf(stderr, "\nBad command line argument.");
         exit(1);
      }
   } else {
     count_position= strlen(argv[1]);
   }
   //--------------------------------------------------------------
   bytes= strdup(argv[1]);
   if (!bytes) {
         fprintf(stderr,"Not enough memory to allocate buffer for bytes.\n");
         exit(1);
   }
   //--------------------------------------------------------------
   trigger= (char*)malloc(count_position);
   if (!trigger) {
         fprintf(stderr,"Not enough memory to allocate buffer for
 trigger.\n");
         free(bytes);
         exit(1);
   }
   for (int cc= 0; cc < count_position; cc++) trigger[cc]= 0;
   //--------------------------------------------------------------
   bytes[0]= '\0';
   pbytes= bytes;
   pargv= argv[1];
   while (*pargv) {
       if (strchr(bytes, *pargv) == 0)
         {
             *pbytes++= *pargv;
             *pbytes= '\0';
         }
     pargv++;
   }
   //--------------------------------------------------------------
   // open a file for output
   sprintf(filename, "%s_%d.txt", argv[1], count_position);
   stream= fopen(filename, "wt+");
   if (!stream)
   {
          fprintf(stderr,"\nError open/create file: %s", filename);
          exit(1);
   }
   fprintf(stream, "\nNumber= %s", argv[1]);
   fprintf(stream, "\nCount position= %d", count_position);
   //--------------------------------------------------------------
   position= count_position - 1;
   count= 1;
   op= PRINT;
 
   while(1)
   {
      switch(op)
      {
           case PRINT:
           // write some data to the file
           fprintf(stream, "\n");
           fprintf(stream, "%u :", count);
 
           for (int j = 0; j < count_position; j++)
           {
                    fprintf(stream,"%c", bytes[trigger[j]]);
           }
 
           if (position != (count_position - 1))
                position= (count_position- 1);
 
           count++;
           op= NEXT_SYMBOL;
           break;
 
           case NEXT_SYMBOL:
           trigger[position]++;
 
           if (trigger[position] == strlen(bytes))
           { // last symbol
                    trigger[position]= 0;
                    op= NEXT_POSITION;
           } else  { // ok
                    op= PRINT;
           }
          break;
 
           case NEXT_POSITION:
           position--;
           if (position < 0)
           { // exit to DOS
                 goto EXIT_TO_DOS;
            } else  { // ok
                 op= NEXT_SYMBOL;
           }
           break;
          }// switch
   } // while(1)
   //-----------------------------------------------------------------
 EXIT_TO_DOS:
   free(bytes);
   free(trigger);
   // close the file
   fclose(stream);
   //-----------------------------------------------------------------
   fprintf(stdout,
 "\n-----------------------------------------------------------------");
   fprintf(stdout, "\nProgramm: %s %s is succefull!", argv[0], argv[1]);
   fprintf(stdout, "\nResult programm save to: [%s]", filename);
   fprintf(stdout, "\nCount= [%d]", count - 1);
   fprintf(stdout,
 "\n-----------------------------------------------------------------");
   //-----------------------------------------------------------------
   return 0;
 }
 
 Будьте здоровы!
 --- ifmail v.2.15dev5
  * Origin: UNKNOWN (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Перебор чисел   Dmitriy Gerasimenko   19 Jul 2002 14:19:40 
 Re: Перебор чисел   Andrey Belyakov   19 Jul 2002 18:52:10 
 Re: Перебор чисел   Dmitriy Gerasimenko   22 Jul 2002 09:08:25 
 Перебор чисел   Georgy Plechanov   22 Jul 2002 11:30:56 
 Re: Пеpебоp чисел   Mike Girkin   19 Jul 2002 19:44:34 
 Перебор чисел   Eugene Anuchin   21 Jul 2002 01:30:04 
 Re: Перебор чисел   Dmitriy Gerasimenko   22 Jul 2002 09:08:26 
 Перебор чисел   Eugene Anuchin   23 Jul 2002 03:03:31 
 Re: Перебор чисел   Dmitriy Gerasimenko   23 Jul 2002 11:22:25 
 Пеpебоp чисел   Alexander Hritonenkov   23 Jul 2002 13:12:42 
 Re: Пеpебоp чисел   Dmitriy Gerasimenko   23 Jul 2002 14:51:09 
 Пеpебоp чисел   Alexander Hritonenkov   23 Jul 2002 18:09:20 
 Re: Пеpебоp чисел   Dmitriy Gerasimenko   23 Jul 2002 14:51:12 
 Re: Перебор чисел   Andrew Ezhguroff   23 Jul 2002 14:24:31 
 Re: Перебор чисел   Dmitriy Gerasimenko   23 Jul 2002 14:51:09 
 Re: Перебор чисел   Andrew Ezhguroff   24 Jul 2002 01:43:03 
 Re: Перебор чисел   Dmitriy Gerasimenko   26 Jul 2002 08:43:38 
 Re: Пеpебоp чисел   Mike Girkin   23 Jul 2002 15:26:22 
 Перебор чисел   Eugene Anuchin   24 Jul 2002 00:12:05 
 Re: Перебор чисел   Dmitriy Gerasimenko   24 Jul 2002 10:07:18 
 Перебор чисел   Eugene Anuchin   25 Jul 2002 00:50:07 
 Re: Перебор чисел   Dmitriy Gerasimenko   25 Jul 2002 09:00:59 
 [*] Перебор чисел   Comoderator Of Ru Algorithms   25 Jul 2002 16:30:12 
 Re: Пеpебоp чисел   Anatoly Svishev   22 Jul 2002 23:31:02 
 Re: Пеpебоp чисел   Dmitriy Gerasimenko   23 Jul 2002 11:22:25 
Архивное /ru.algorithms/89683d64ccaa.html, оценка 3 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional