Official
A - Lacked Number Editorial by en_translator
For each of 0
, 1
, \(\ldots\) , and 9
, maintain a flag that signifies whether the character appears in the string \(S\), and finally output the missing one. There are various ways to convert a character or a string to a number depending on programming languages (or even in a single language); it may be useful to remember your favorite way to do so.
Sample code in C++:
#include<bits/stdc++.h>
using namespace std;
int main(void) {
string S;
bool flag[10];
for (int i = 0; i < 10; i++)flag[i] = true;
cin >> S;
for (int i = 0; i < 9; i++)flag[((int)(S[i] - '0'))] = false;
for (int i = 0; i < 10; i++)if (flag[i])cout << i << endl;
return 0;
}
Sample code in Python:
S=input()
flag=[True for i in range(10)]
for i in range(9):
flag[int(S[i])]=False
for i in range(10) :
if(flag[i]):
print(i)
By the way, the answer can be found by subtracting all the given digits from \(0+1+\cdots +9=45\).
Sample code in C++:
#include<bits/stdc++.h>
using namespace std;
int main(void) {
string S;
cin >> S;
int ans = 45;
for (int i = 0; i < 9; i++)ans -= ((int)(S[i] - '0'));
cout << ans << endl;
return 0;
}
posted:
last update: