E - AtCoder Beginner Contest 999
Problem Statement
Cat Snuke is learning to write characters. Today, he practiced writing digits 1
and 9
, but he did it the other way around.
You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit 1
with 9
and each digit 9
with 1
in nn.
Constraints
- 111≤n≤999
- n is an integer consisting of digits
1
and9
.
Input
Input is given from Standard Input in the following format:
n
Output
Print the integer obtained by replacing each occurrence of 1
with 9
and each occurrence of 9
with 1
in nn.
Sample 1
Inputcopy | Outputcopy |
---|---|
119 | 991 |
Replace the 9
in the ones place with 1
, the 1
in the tens place with 9
and the 1
in the hundreds place with 9
. The answer is 991
.
Sample 2
Inputcopy | Outputcopy |
---|---|
999 | 111 |
看代码:
#include<stdio.h>
int a[1000];
int main(){
int n,i,t=0;
scanf("%d",&n);
if(n<=110 || n >= 1000)
return 0;
for(i=0;i<3;i++){
a[t++]=n%10;
n/=10;
}
for(t=3;t>=0;t--){
if(a[t] == 1)
printf("9");
if(a[t] == 9)
printf("1");
}
}
这个题一开始我没有把三位整数抽进数组里,而是一个一个输出,出来顺序是反的,本来不想抽进数组(因为感觉这样做比较麻烦),但最后实在没想出更好的方法了。也算是复习下如何把整数的每位数抽进数组里