Advertisement
Guest User

pesci2

a guest
Jul 29th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string>
  3.  
  4. char descrizione[10000];
  5. std::string S;
  6.  
  7. int gira(int N)
  8. {
  9.     char j;
  10.     int k = 0;
  11.     for(int i=0; i<N; i++)
  12.     {
  13.         if(descrizione[i] != '(' && descrizione[i] != ')') S.push_back(descrizione[i]);
  14.     }
  15.     j = S[0];
  16.     for(int i=0; i<S.size()-1; i+=2)
  17.     {
  18.         if(S[i] == j) k++;
  19.     }
  20.     return (S.size()/2)-k;
  21. }
  22.  
  23. int main()
  24. {
  25.     FILE *fr, *fw;
  26.     int N;
  27.  
  28.     fr = fopen("input.txt", "r");
  29.     fw = fopen("output.txt", "w");
  30.  
  31.     fscanf(fr, "%d\n", &N);
  32.     fgets(descrizione, N, fr);
  33.     fprintf(fw, "%d\n", gira(N));
  34.  
  35.     fclose(fr);
  36.     fclose(fw);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement