Advertisement
Kosty_Fomin

Untitled

Nov 29th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <sys/stat.h>
  5.  
  6. struct answers_1{
  7.     char* ans;
  8. };
  9.  
  10. struct answers_1  get_file_name(int *mas, int x);
  11.  
  12.  
  13. int main (void)
  14. {
  15.     struct answers_1  answers;
  16.     char* path = (char*) malloc( 256 );
  17.     int x = 0, buf = 0,i=0,b;
  18.    
  19.     printf("Input file name:\n");
  20.     scanf("%s",path);
  21.    
  22.     FILE *in;
  23.     in = fopen(path, "r");
  24.    
  25.     if (in == NULL) {
  26.         exit(1);
  27.     }
  28.  
  29.    
  30.     while ((fscanf(in, "%d", &b)!=EOF)) {
  31.         x++;
  32.  
  33.     }
  34.     rewind(in);
  35.    
  36.    
  37.     int mas[x];
  38.  
  39.     for(i=0;i<x;i++){
  40.        
  41.         fscanf(in, "%d", &buf);
  42.         mas[i] = buf;
  43.        
  44.     }
  45.     answers = get_file_name(mas,x);
  46.     printf("%s\n", answers.ans);
  47.    
  48. }
  49.  
  50.  
  51.  
  52.  
  53. struct answers_1  get_file_name(int *mas, int x){
  54.    
  55.     struct answers_1  answersf;
  56.     answersf.ans = "YES";
  57.    
  58.      for(int i=0;i<x/2;i++){
  59.          if (mas[i]!=mas[x-i-1]){
  60.              answersf.ans = "NO";
  61.              break;
  62.          }
  63.      }
  64.     return answersf;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement