Official

A - delete . Editorial by en_translator


For beginners

The sought string, \(T\), can be obtained by the following procedure:

  • Let \(T\) be an empty string.
  • Inspect each character of \(S\) in order. If it is not ., append it to the tail of \(T\).

For example, for \(S=\) a.c., the string \(T\) is constructed as follows:

  • Let \(T\) be an empty string.
  • The \(1\)-th character of \(S\) is a, so append it to the tail of \(T\). Now \(T=\) a.
  • The \(2\)-th character of \(S\) is ., so do nothing. Still \(T=\) a.
  • The \(3\)-th character of \(S\) is c, so append it to the tail of \(T\). Now \(T=\) ac.
  • The \(4\)-th character of \(S\) is ., so do nothing. Still \(T=\) ac.
  • Finally, \(T=\) ac.

Implementations of this procedure into code follow.

Sample code (Python3)

S = input()
T = ""
for c in S:
  if c != '.':
    T += c
print(T)

Sample code (C++)

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    string t;
    for (char c : s) {
        if (c != '.') {
            t += c;
        }
    }
    cout << t << endl;
    return 0;
}

Some programming languages is capable of implementing it concisely without using a for statement.

Sample code (Python3)

print(input().replace('.', ''))

Sample code (C++)

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    string s;
    cin >> s;
    s.erase(remove(s.begin(), s.end(), '.'), s.end());
    cout << s << endl;
    return 0;
}

posted:
last update: