区域赛选拔题--B题--Adding Sevens
来源:互联网 发布:淘宝申请实拍保护 编辑:程序博客网 时间:2024/06/08 19:02
B. Adding Sevens
A seven segment display, similar to the one shown on the right, is composed of seven light-emitting elements. Individually on or off, they can be combined to produce 127 different combinations, including the ten Arabic numerals. The figure below illustrates how the ten numerals are displayed. 7-seg displays (as they're often abbreviated) are widely used in digital clocks, electronic meters, and calculators.
A 7-seg has seven connectors, one for each element, (plus few more connectors for other electrical purposes.) Each element can be turned on by sending an electric current through its pin. Each of the seven pins is viewed by programmers as a single bit in a 7-bit number, as they are more comfortable dealing with bits rather than electrical signals. The figure below shows the bit assignment for a typical 7-seg, bit 0 being the right-most bit.
For example, in order to display the digit 1, the programmer knows that only bits 1 and 3 need to be on, i.e. the 7-bit binary number to display digit 1 is ``0001010", or 10 in decimal. Let's call the decimal number for displaying a digit, its display code, or just code for short. Since a 7-seg displays 127 different configurations, display codes are normally written using 3 decimal places with leading zeros if necessary, i.e. the display code for digit 1 is written as 010.
In a 9-digit calculator, 9 7-seg displays are stacked next to each other, and are all controlled by a single controller. The controller is sent a sequence of 3n digits, representing n display codes, where 0 < n < 10 . If n < 9 , the number is right justified and leading zeros are automatically displayed. For example, the display code for 13 is 010079 while for 144 it is 010106106
Write a program that reads the display codes of two numbers, and prints the display code of their sum.
Input
Your program will be tested on one or more test cases. Each test case is specified on a single line in the form of A +B = where bothA and B are display codes for decimal numbers a and b respectively where 0 < a , b < a + b < 1, 000, 000, 000 . The last line of the input file is the word ``BYE'' (without the double quotes.)
Output
For each test case, print A +B =C where C is the display code for a + b .
Sample Input
010079010+010079=106010+010=BYE
Sample Output
010079010+010079=010106106106010+010=106093
大数相加
ps:英文一直是做区域赛题的瓶颈,不过个人认为要抓住细节和关键点。
题意:按照题目给出的信息计算灯亮的编码序列号,注意是7位编码,如题,灯显示1的时候,必须触及1和3,ans=2^1+2^3=0001010(二进制)=10(十进制)。
灯显示3的时候,必须触及0,3,6,1,2,ans=2^0+2^3+2^6+2^1+2^2=1001111(二进制)=79(十进制)。
原理搞清楚,接下来就是锻炼细节和思维方面了
此题扣了很久,
#include<cstdio>#include<cstring>#include <iostream>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;char ss[110], aa[50], bb[50], AA[15], BB[15];int str1[128];char *str2[11] = {"063","010","093", "079", "106", "103","119","011", "127", "107"};void fun(){ str1[63] = 0; str1[10] = 1; str1[93] = 2; str1[79] = 3; str1[106] = 4; str1[103] = 5; str1[119] = 6; str1[11] = 7; str1[127] = 8; str1[107] = 9;}int main(){ fun(); while(scanf("%s", ss) && strcmp(ss, "BYE") != 0) {// memset(aa, 0, sizeof(aa));// memset(bb, 0, sizeof(bb)); mem(aa,0); mem(bb,0); getchar(); int ans = 0; int k; for(k = 0; ss[k] != '+'; ++k) aa[ans++] = ss[k]; ans= 0; k++; for(; ss[k] != '='; ++k) bb[ans++] = ss[k];// memset(AA, 0, sizeof(AA));// memset(BB, 0, sizeof(BB)); mem(AA,0); mem(BB,0); int cnt1 = 0, j = 0,temp = 0,i; for(i = 0; i <= strlen(aa); ++i)//十进制表示 { if(j == 3) { //printf("temp=%d\n", temp); AA[cnt1++] = str1[temp]+'0'; temp = 0; j = 0; } temp *= 10; temp += aa[i]-'0'; j++; } int cnt2 = 0; j = 0; temp = 0; for(i = 0; i <= strlen(bb); ++i) { if(j == 3) { // printf("temp=%d\n", temp); BB[cnt2++] = str1[temp]+'0'; temp = 0; j = 0; } temp *= 10; temp += bb[i]-'0'; j++; } int a1[15], b1[15];// memset(a1, 0, sizeof(a1));// memset(b1, 0, sizeof(b1)); mem(a1,0); mem(b1,0); int va1 = 0,va2=0; for(i = strlen(AA)-1; i >= 0; --i) a1[va1++] = AA[i]-'0'; for(i = strlen(BB)-1; i >= 0; --i) b1[va2++] = BB[i]-'0'; int vv= va1>va2? va1:va2; for(i = 0; i < vv; ++i) a1[i] += b1[i]; int len = vv; for(i = 0; i < vv; ++i) { if(i == vv-1 && a1[i]>=10) len++; if(a1[i] >= 10) { a1[i+1] += a1[i]/10; a1[i] %= 10; } } printf("%s+%s=", aa, bb); for(int i = len-1; i >=0 ; --i) printf("%s", str2[a1[i]]); printf("\n"); } return 0;}
- 区域赛选拔题--B题--Adding Sevens
- 2597: 编程题B-选拔飞行员
- YTU 2597: 编程题B-选拔飞行员
- ytu 2597: 编程题B-选拔飞行员
- OJ 2597: 编程题B-选拔飞行员
- 区域赛选拔题G--Think I'll Buy Me a Football Team
- 区域赛选拔题--Moon Game--计算几何&&判断平面点集组成的凸边行的个数
- 第六届蓝桥杯大赛个人赛(软件类)校内选拔题目\Java大学B组\1题
- 第六届蓝桥杯大赛个人赛(软件类)校内选拔题目\Java大学B组\2题 调和级数
- Jesus Is Here(区域赛网络赛选拔)
- HDU 4465 Candy 概率 (2012成都区域赛B题)
- EOJ Monthly 2017.12 (暨 ECNU 12 月内部选拔) B题
- EOJ Monthly 2017.12 (暨 ECNU 12 月内部选拔) 总结 A B C G1题题解
- 【选拔题】2009南海集训队初中选拔题一
- 蓝桥杯校内选拔第一题
- 蓝桥杯校内选拔第二题
- 蓝桥杯校内选拔第三题
- 蓝桥杯校内选拔第四题
- (原)MongoDB在系统中的使用
- R语言机器学习笔记——垃圾邮件分类
- 四色猜想与连连看
- Android平台下利用zxing实现二维码开发
- android困惑之UI---imageView实现对图片的选取,和裁剪功能。。。。
- 区域赛选拔题--B题--Adding Sevens
- 弹出居中的div层
- 蛮力法:设计算法求解字符串的模式匹配问题,并编程实现。
- 【木头Cocos2d-x 037】retain和release倒底怎么玩?
- linux鸟哥私房菜学习笔记之四-script
- jquery datepicker
- 各种指令
- 函数版星号图2(修改)
- 四个开源商业智能平台比较(四)