ACM2022入门题单-基础E

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 and 9.

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

InputcopyOutputcopy
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

InputcopyOutputcopy
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");
	}
}

这个题一开始我没有把三位整数抽进数组里,而是一个一个输出,出来顺序是反的,本来不想抽进数组(因为感觉这样做比较麻烦),但最后实在没想出更好的方法了。也算是复习下如何把整数的每位数抽进数组里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

511511511

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值