substr and find

Lab C++ Beginner 10 points

Read an email address. Print the user part (before @) and the domain (after it). If there is no @, print invalid.

Input

One word.

Output

Two lines, or invalid.

Example

Input

ada@example.com

Output

ada
example.com
Sample input available Sample output available
Editor
C++

Hints

find returns string::npos when not found.

substr(start, length) or substr(start) to the end.

Solution explanation

size_t is the unsigned type used for string positions.

Show solution
#include <iostream>
#include <string>
using namespace std;

int main() {
    string email;
    cin >> email;
    size_t at = email.find('@');
    if (at == string::npos) {
        cout << "invalid\n";
    } else {
        cout << email.substr(0, at) << "\n" << email.substr(at + 1) << "\n";
    }
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD