Official
A - delete . Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
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.
S = input()
T = ""
for c in S:
if c != '.':
T += c
print(T)
#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.
print(input().replace('.', ''))
#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: