1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /*
- * Copyright (C) 2020, 2019, 2018, 2017 Girish M
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
- /*-----------------------------------
- Name: Girish M
- Roll number: cs1713
- Date: 25 July 2017
- Program description:Write a program to find the number of (possibly overlapping)
- occurrences of the sequence B in A.
- Acknowledgements:
- ------------------------------------*/
- #include <stdio.h>
- int main()
- {
- int arr1[] = {1, 2, 2, 2, 2, 1, 2, 3, 3, 4, 3, 1, 2, 3, 1, 2, 3, 2, 1, 1};
- int arr2[] = {2, 2, 2};
- int i=0, j=0, k=0, match=0;
- while(j != 20)
- {
- if(arr1[k] == arr2[i])
- {
- i++;
- k++;
- }
- else
- {
- i=0;
- }
- if(i == 3)
- {
- match++;
- i=0;
- }
- k=j;
- j++;
- }
- printf("\nNo. of matches %d\n", match);
- return 0;
- }
|