-3

i need to change some character into numbers for example:

I = 1

R = 2

E = 3

A = 4

S = 5

G = 6

T = 7

B = 8

P = 9

O = 0

input example: HELLO IM GOOD

output example: H3LL0 1M G00D

2 Answers2

1

Are you trying to make us do your homework?

Anyhow, there are multiple possibilities.

  1. For the starter student - The most basic one is looping through your string and replacing each needed char with a new one (you can use a switch case, look-up-tables, etc).
  2. You can convert to a string and use it's methods as such:

    string s;
    s="HELLO IM GOOD"
    s.replace('I,'1')
    s.replace('R,'2')
    .
    .
    .
    cout << s; //print solution
    
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Lior
  • 284
  • 1
  • 6
0

This code helps:)

#include <iostream>
#include<stdio.h>
using namespace std;

int main() {
    string s;
    getline (cin, s); //used to get string input with spaces
    string s1 = "OIREASGTBP";
    string s2 = "0123456789";

    for (int i=0; i<s.size(); i++)
    {
        int a = s1.find(s[i]);
        if(a != -1)
        {
             s[i] = s2[a];
        }
    }
    cout<<s;
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
VJAYSLN
  • 473
  • 4
  • 12