颜色反转

题目链接: http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3340&konwledgeId=40

解题思路: 直接模拟。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int getOrder(char ch)
 5 {
 6     if (isdigit(ch)) return ch-'0';
 7     return ch-'A'+10;
 8 }
 9 
10 char getChar(int x)
11 {
12     if (x<10) return '0' + x;
13     return 'A' + x - 10;
14 }
15 
16 int char2int(char *s)
17 {
18     return getOrder(s[0])*16 + getOrder(s[1]);
19 }
20 
21 void int2char(int x, char *s)
22 {
23     int i = x / 16;
24     int j = x % 16;
25     s[0] = getChar(i);
26     s[1] = getChar(j);
27 }
28 
29 int main()
30 {
31     char s[10];
32     while (scanf("%s", s) != -1)
33     {
34         int x = char2int(s+1);
35         int2char(255-x,s+1);
36         x=char2int(s+3);
37         int2char(255-x,s+3);
38         x=char2int(s+5);
39         int2char(255-x,s+5);
40         printf("%s\n",s);
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/djingjing/p/8992996.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值