1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cctype>
using namespace std;
main(){
string str[30] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "forteen", "fifteen", "sixteen", "seventeen", "eighteen",
"nineteen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety",
"hundred", "thousand", "million"}, str1;
int num[30] = {1, 2, 3, 4, 5, 6 , 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ,19, 20, 30, 40, 50, 60, 70,
80, 90, 100, 1000, 1000000};
fstream in("english_num.in");
vector<string>vstr;
while(getline(in, str1)){
int ctr = 0, ctr1 = 0;
for(int i = 0; i != str1.length(); i++) ///checks if its a sentence
if(isspace(str1[i]))
ctr1++;
if(ctr1 == 0){ ///if its not a sentence then it prints the word
for(int i = 0; i != 29; i++)
if(str1 == str[i])
cout<<str[i]<<endl;
}
else
for(int i = 0; i != str1.length(); i++){ ///separating process
if(isspace(str1[i])){
vstr.push_back(str1.substr(ctr, i));
ctr = i;
}
}
if(!vstr.empty()){ ///prints the seperated words
for(int i = 0; i != vstr.size(); i++){
if(vstr[i] == "negative")
cout<<"negative ";
for(int j = 0; j != 29; j++)
if(vstr[i] == str[j])
cout<<str[i]<<" ";
}
cout<<endl;
vstr.clear();
}
}
}
|