[ create a new paste ] login | about

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

C, pasted on Jun 7:
/*
Từ là 1 hoặc nhiều ký tự khác khoảng trắng
VD: Nam Son
=> Có 2 từ là "Nam" và "Son"
 */
#include<iostream>
#include<string>
using namespace std;
int DemSoTu(string s)
{
	int length = s.length();
	int dem = 0;

	// [] => toán tử lấy chỉ số
	if(s[0] != ' ')
	{
		dem = 1;
	}
	for(int i = 0; i < length - 1; i++)
	{
		if(s[i] == ' ' && s[i + 1] != ' ')
		{
			dem++;
		}
	}
	return dem;
}
int main()
{
	string s = "   Nam  Son   ";

	int sotu = DemSoTu(s);
	cout << "\nSo tu " << sotu;

	system("pause");
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
Line 18: error: iostream: No such file or directory
Line 16: error: string: No such file or directory
Line 8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
Line 9: error: expected ')' before 's'
In function 'main':
Line 30: error: 'string' undeclared (first use in this function)
Line 30: error: (Each undeclared identifier is reported only once
Line 30: error: for each function it appears in.)
Line 30: error: expected ';' before 's'
Line 32: error: 's' undeclared (first use in this function)
Line 33: error: 'cout' undeclared (first use in this function)


Create a new paste based on this one


Comments: