Pages

Saturday, June 2, 2012

10921 - Find the Telephone


//
// main.cpp
// 10921 - Find the Telephone
//
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;


void doit(char a);
string *str=new string[8];
using namespace std;
int main (int argc, const char * argv[])
{

str[0]="ABC", str[1]="DEF", str[2]="GHI", str[3]="JKL", str[4]="MNO", str[5]="PQRS", str[6]="TUV", str[7]="WXYZ";
string input;
while (getline(cin, input)){
for_each(input.begin(), input.end(), doit);
cout<<endl;
}
return 0;
}


void doit(char a){
bool done=false;
for (int i=0; i<8; i++) {
if (count(str[i].begin(), str[i].end(), a)) {
cout<<i+2;
done=true;
}
}

if (!done) {
cout<<a;
}
}

No comments:

Post a Comment