[ create a new paste ] login | about

Link: http://codepad.org/3S1aZJ21    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Mar 9:
//CountString
//cho 1 cau, 1 xau ki tu. dem xem trong cau co bao nhieu xau nhu the
#include <iostream>
#include <stdio.h>
#include <conio.h>

using namespace std;
int main()
{
	int n;
	char subString[6];
	char sentence[500];
	freopen("Testcase.txt", "r", stdin);
	/*for(int testcase = 1; testcase <= 10; testcase++)
	{*/
		int count = 0;
		cin >> n;
		
		gets(subString);
		
		
		gets(sentence);
		int a = 0, b = 0;
		while(subString[a] != '\0')
			a++;
		while(sentence[b] != '\0')
			b++;

		for(int i=b-1;i>=0;i--)
		{
			for(int j=a-1;j>=0;j--)
			{
				if(sentence[i]==subString[j])
				{
					if(j==0)
						count++;
					i--;
				}
			}
		}
		/*cout << "#" << testcase << " " << count << endl;*/
		cout << count;
	/*}*/
	getch();
	return 0;
}


Output:
1
2
3
4
Line 18: error: conio.h: No such file or directory
In function 'int main()':
Line 44: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: