Make a vector holding the ten string values "zero", "one",..."nine".
Use that in a programm that converts a digit to its corresponding spell-out value; e.g.,the input 7 gives the output seven.Have the same program using the same input loop,convert spelled-out numbers into their digit form;e.g., the input seven gives the output 7.
Το πρώτο μέρος το έχω λύσει.
Για το δεύερο έχω κάνει μια προσπάθεια αλλά δεν βγαίνει.
Παρακάτω παραθέτω τον κώδικα.
- Κώδικας: Επιλογή όλων
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open(){char ch; cin>>ch;}
int main()
{
vector<string>spell_out(10);
spell_out[0]="zero";
spell_out[1]="one";
spell_out[2]="two";
spell_out[3]="three";
spell_out[4]="four";
spell_out[5]="five";
spell_out[6]="six";
spell_out[7]="seven";
spell_out[8]="eight";
spell_out[9]="nine";
vector<int>number(10);
number[0]=0;
number[1]=1;
number[2]=2;
number[3]=3;
number[4]=4;
number[5]=5;
number[6]=6;
number[7]=7;
number[8]=8;
number[9]=9;
string spell;
while(cin>>spell){
for (int i=0;i>spell_out.size();i++)
if(spell_out[i]==spell)
cout<<number[i]<<"\n";}
keep_window_open();
}