Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Same Letters

By: a guest on Jan 25th, 2011  |  syntax: C++  |  size: 2.27 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. int letter2num(char l)
  9. {
  10.         if(l=='a') return 0;
  11.         if(l=='b') return 1;
  12.         if(l=='c') return 2;
  13.         if(l=='d') return 3;
  14.         if(l=='e') return 4;
  15.         if(l=='f') return 5;
  16.         if(l=='g') return 6;
  17.         if(l=='h') return 7;
  18.         if(l=='i') return 8;
  19.         if(l=='j') return 9;
  20.         if(l=='k') return 10;
  21.         if(l=='l') return 11;
  22.         if(l=='m') return 12;
  23.         if(l=='n') return 13;
  24.         if(l=='o') return 14;
  25.         if(l=='p') return 15;
  26.         if(l=='q') return 16;
  27.         if(l=='r') return 17;
  28.         if(l=='s') return 18;
  29.         if(l=='t') return 19;
  30.         if(l=='u') return 20;
  31.         if(l=='v') return 21;
  32.         if(l=='w') return 22;
  33.         if(l=='x') return 23;
  34.         if(l=='y') return 24;
  35.         if(l=='z') return 25;
  36.         if(l==',') return 26;
  37.         if(l=='.') return 27;
  38.         if(l== ' ') return 28;
  39.  
  40.         return 29;
  41. }
  42.  
  43. void compare(string t1,string t2)
  44. {
  45.         vector <int> v(30,0);
  46.         vector <int> w(30,0);
  47.         for(int i=0;i<t1.size();i++)
  48.         {
  49.                 v[letter2num(t1[i])]+=1;
  50.         }
  51.         for(int i=0;i<t2.size();i++)
  52.         {
  53.                 w[letter2num(t2[i])]+=1;
  54.         }
  55.         int letters=0;
  56.         int punctuation=0;
  57.         int spaces=0;
  58.         for(int i=0;i<26;i++)
  59.         {
  60.                 if(v[i] == w[i]) letters+=1;
  61.                 cout<<v[i]<<" "<<w[i]<<endl; //This shows the number of letters and symbols in both of them
  62.         }
  63.         if( (v[26] == w[26]) && (v[27] == w[27])) punctuation = 2;
  64.         if( (v[28] == w[28]) ) spaces = 1;
  65.        
  66.         cout<<"They have same: ";cout<<letters<<endl;
  67.         if(letters == 26) cout<<"letters ";
  68.         if(punctuation == 2) cout<<"punctuation ";
  69.         if(spaces == 1) cout<<"spaces ";
  70.        
  71. }
  72.  
  73. int main()
  74. {
  75.         string t1, t2;
  76.         /*cout<<"Text 1"<<endl;
  77.         getline (cin, t1, '\n');
  78.         cout<<endl      <<"Text 2"<<endl;
  79.         getline (cin, t2, '\n');*/
  80.  
  81.         t1 = "this text and the one beside it are equal. i wrote this one first, and then i gave it to my friend christian bok and asked him to generate a new text using every letter and every punctuation mark that i used in mine. the other text is his.";
  82.         t2 = "micah lexier requested in advance that i reinvent his text. so i unknotted it and reknitted it into this very form, but then i began to think that his message had alredy resewn a touted art of genuine poetry. his eerie text was mine.";
  83.        
  84.        
  85.         //Manual counting A's in #1: 11111 11111 111
  86.         //Manual counting A's in #2: 11111 11111 11
  87.         compare(t1,t2);
  88.  
  89.         return 0;
  90. }
clone this paste RAW Paste Data