Advertisement
Waliul

vyrevy problem er solution

Oct 26th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     FILE *fp, *fpw;
  7.     fp = fopen("F:\\inputstr.txt", "r");
  8.     fpw = fopen("F:\\outputstr.txt", "w");
  9.     char str[50], rev[50], t;
  10.     fscanf(fp,"%s", str);
  11.     int l = strlen(str);
  12.     int i, j, a = 0, count, mid;
  13.     if((l % 2) == 0)
  14.     {
  15.         for(i = 0; i < l / 2; i++)
  16.         {
  17.             for(j = i + 1; j <l; j++)
  18.             {
  19.                 if(str[i] == str[j])
  20.                 {
  21.                     t = str[l - i -1];
  22.                     str[l - i -1] = str[j];
  23.                     str[j] = t;
  24.                 }
  25.             }
  26.         }
  27.         strcpy(rev, str);
  28.         strrev(rev);
  29.         if(strcmp(str, rev) == 0)
  30.         {
  31.             printf("YES", str);
  32.             fprintf(fpw, "%s", str);
  33.         }
  34.         else
  35.         {
  36.             fprintf(fpw, "NO");
  37.         }
  38.     }
  39.     else
  40.     {
  41.         for(i = 0; i < l; i++)
  42.         {
  43.             count = 1;
  44.             for(j = 0; j < l; j++)
  45.             {
  46.                 if(i != j)
  47.                 {
  48.                     if(str[i] == str[j])
  49.                     {
  50.                         count++;
  51.                         break;
  52.                     }
  53.                 }
  54.             }
  55.             if((j == l) && (count == 1))
  56.             {
  57.                 a = i;
  58.                 break;
  59.             }
  60.         }
  61.         mid = l / 2;
  62.         t = str[mid];
  63.         str[mid] = str[a];
  64.         str[a] = t;
  65.         for(i = 0; i < ((l / 2) - 1); i++)
  66.         {
  67.             for(j = i + 1; j <l; j++)
  68.             {
  69.                 if(str[i] == str[j])
  70.                 {
  71.                     t = str[l - i -1];
  72.                     str[l - i -1] = str[j];
  73.                     str[j] = t;
  74.                 }
  75.             }
  76.         }
  77.         strcpy(rev, str);
  78.         strrev(rev);
  79.         if(strcmp(str, rev) == 0)
  80.         {
  81.             printf("YES", str);
  82.             fprintf(fpw, "%s", str);
  83.         }
  84.         else
  85.         {
  86.             fprintf(fpw, "NO");
  87.         }
  88.     }
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement