Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
#include <iostream>
using namespace std;
#include <cstring>
#include <sstream>
#include <vector>

string str = "The pyramids of Egypt were built more than three thousand years ago, and no one knows how. The conventional picture is that tens of thousands of slaves dragged stones on sledges. But there is no evidence to back this up. Now a Californian software consultant called Maureen Clemmons has suggested that kites might have been involved. While perusing a book on the monuments of Egypt, she noticed a hieroglyph that showed a row of men standing in odd postures. They were holding what looked like ropes that led, via some kina of mechanical system, to a giant bird in the sky. She wondered if perhaps the bird was actually a giant kite, and the men were using it to lift a heavy object.";

struct word {
	int count = 1;
	string a;
};
typedef struct word wo;

bool comp(string s1, string s2)
{

	for (int i = 0; i < s1.size(); i++)
		s1[i] = toupper(s1[i]);

	for (int i = 0; i < s2.size(); i++)
		s2[i] = toupper(s2[i]);

	if (s1.compare(s2) == 0)
	{
		return true;
	}

	return false;
}

int main() {
	vector<wo> arr;
	int k = 0;
	stringstream ss(str);
	string tmp;
	while (ss >> tmp) {
		arr[k].a = tmp;
		for (int i = 0; i < k; i++) {
			if (comp(arr[k].a, arr[i].a) && k != 0) {
				arr[i].count++;
				k--;
				break;
			}
		}
	}
	for (wo item : arr) {
		cout << item.a << " : " << item.count << endl;
	}

	return 0;
}