fork download
  1. #include <iostream>
  2. //#include <fstream>
  3. #include <string>
  4. #include <ctype.h>
  5. using namespace std;
  6.  
  7. //New portion
  8. int main(int argc, char *argv[]) {
  9. //File Paths
  10. //ifstream fp;
  11. istream &fp = cin;
  12. //fp.open(argv[1]);
  13. //if (!fp.is_open()) {
  14. // cout << "Error No file" << endl;
  15. // return 0;
  16. //}
  17.  
  18. string wordArr[10000];
  19. string words;
  20. string temp;
  21. int wordCount = 0;
  22. while ((fp >> words) && (wordCount < 10000)) {
  23. for (int i = 0; i < words.length(); ++i) {
  24. if (!isalpha(words[i])) {
  25. wordArr[wordCount++] = words.substr(0, i);
  26. if (wordCount == 10000) break;
  27. ++i;
  28. while ((i < words.length()) && (!isalpha(words[i]))) {
  29. ++i;
  30. }
  31. words.erase(0, i);
  32. i = -1;
  33. }
  34. }
  35. if (words.length() > 0) {
  36. wordArr[wordCount++] = words;
  37. }
  38. }
  39. cout << "Number of words found was: " << wordCount << endl;
  40.  
  41. // makes all lower
  42. for(int k=0; k<wordCount;k++){ //need to find size of array
  43. for(int l=0; l<wordArr[k].length(); l++){
  44. wordArr[k][l] = tolower(wordArr[k][l]);
  45. }
  46. }
  47.  
  48. //unique count
  49. string tempArr[10000];
  50. int unique=0;
  51. for(int m=0; m<wordCount;m++ ) {
  52. int oldWord=0;
  53. for (int n = 0; n < unique; n++) {
  54. if (wordArr[m] == tempArr[n]) {
  55. oldWord = 1;
  56. break;
  57. }
  58. }
  59. if(oldWord==0){
  60. tempArr[unique++] = wordArr[m];
  61. }
  62. }
  63. cout << "Unique word count is: " << unique << endl;
  64. }
Success #stdin #stdout 0s 15736KB
stdin
Cryptography is both the practice and study of the techniques used to communicate and/or store information or data privately and securely, without being intercepted by third parties. This can include processes such as encryption, hashing, and steganography. Until the modern era, cryptography almost exclusively referred to encryption, but now cryptography is a broad field with applications in many critical areas of our lives.
stdout
Number of words found was: 64
Unique word count is: 52