Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void spaceCount(string, int*);
  6. void showWords(string[],int);
  7.  
  8. int main(){
  9. string fullString;
  10.  
  11. int fSpace = 0, point = 0, each = 0, pos, indef = 0, numb = 0;
  12.  
  13. cout << "type a sentense :\n";
  14. getline(cin,fullString);
  15. fullString += ' ';
  16. spaceCount(fullString,&fSpace);
  17.  
  18. string *words = new string[fSpace];
  19.  
  20. do {
  21. pos = fullString.find(" ");
  22. words[each] = fullString.substr(point, pos);
  23. fullString.erase(point, pos + 1);
  24. each++;
  25. } while (!fullString.empty());
  26.  
  27. for (int i = 0; i < each-1; i++){
  28. for (int j = i + 1; j < each; j++){
  29. if (words[i] == words[j]){
  30. words[i].clear();
  31. words[j].clear();
  32. indef++;
  33. }
  34. }
  35. }
  36.  
  37. for (int k = 0; k < each; k++){
  38. for (int i = 0; i < words[k].length(); i++){
  39. for (int j = i + 1; j < words[k].length(); j++){
  40. if (words[k].at(i) == words[k].at(j)){
  41. words[k].at(j) = 0;
  42. words[k].at(i) = 0;
  43. }
  44. }
  45. }
  46. }
  47.  
  48. showWords(words, each);
  49. delete []words;
  50.  
  51. system("pause");
  52. return 0;
  53. }
  54.  
  55. void spaceCount(string currString,int *space){
  56. for (int i = 0; i < currString.length(); i++){
  57. if (currString.at(i) == ' ')
  58. *space += 1;
  59. }
  60. }
  61. void showWords(string word[],int eac){
  62.  
  63. for (int i = 0; i < eac; i++)
  64. cout << word[i] << " ";
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement