Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- FILE *fp, *fpw;
- fp = fopen("F:\\inputstr.txt", "r");
- fpw = fopen("F:\\outputstr.txt", "w");
- char str[50], rev[50], t;
- fscanf(fp,"%s", str);
- int l = strlen(str);
- int i, j, a = 0, count, mid;
- if((l % 2) == 0)
- {
- for(i = 0; i < l / 2; i++)
- {
- for(j = i + 1; j <l; j++)
- {
- if(str[i] == str[j])
- {
- t = str[l - i -1];
- str[l - i -1] = str[j];
- str[j] = t;
- }
- }
- }
- strcpy(rev, str);
- strrev(rev);
- if(strcmp(str, rev) == 0)
- {
- printf("YES", str);
- fprintf(fpw, "%s", str);
- }
- else
- {
- fprintf(fpw, "NO");
- }
- }
- else
- {
- for(i = 0; i < l; i++)
- {
- count = 1;
- for(j = 0; j < l; j++)
- {
- if(i != j)
- {
- if(str[i] == str[j])
- {
- count++;
- break;
- }
- }
- }
- if((j == l) && (count == 1))
- {
- a = i;
- break;
- }
- }
- mid = l / 2;
- t = str[mid];
- str[mid] = str[a];
- str[a] = t;
- for(i = 0; i < ((l / 2) - 1); i++)
- {
- for(j = i + 1; j <l; j++)
- {
- if(str[i] == str[j])
- {
- t = str[l - i -1];
- str[l - i -1] = str[j];
- str[j] = t;
- }
- }
- }
- strcpy(rev, str);
- strrev(rev);
- if(strcmp(str, rev) == 0)
- {
- printf("YES", str);
- fprintf(fpw, "%s", str);
- }
- else
- {
- fprintf(fpw, "NO");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement