区域赛选拔题--B题--Adding Sevens

来源:互联网 发布:淘宝申请实拍保护 编辑:程序博客网 时间:2024/06/08 19:02

                   B. Adding Sevens

 链接:http://www.bnuoj.com/v3/contest_show.php?cid=5512#problem/B
64-bit integer IO format: %lld      Java class name: Main

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.

\epsfbox{p4362a.eps}

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.

\epsfbox{p4362b.eps}

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;}


 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 六个月宝宝粘人怎么办 11个月宝宝粘人怎么办 一岁宝宝脸冻了怎么办 2个月宝宝粘人怎么办 8个月宝宝粘人怎么办 9个月宝宝粘人怎么办 8个月婴儿粘人怎么办 4个月宝宝粘人怎么办 7个月宝宝粘人怎么办 8个月孩子太粘人怎么办 7个月宝宝太粘人怎么办 两岁宝宝粘人怎么办 孩子屁股被打了怎么办 长期被骂的孩子怎么办 儿童感冒咳嗽怎么办最有效 打了排卵针不排卵怎么办 孩孑上课不专心怎么办 4岁上课不听讲怎么办 孩子上课不认真听讲怎么办 孩子做什么都慢怎么办 7岁上课不听讲怎么办 打孩子脸肿了怎么办 一岁宝宝太调皮怎么办 怀孕早期喝了酒怎么办 怀孕期间喝了酒怎么办 一岁宝宝多动怎么办 3岁前儿童多动症怎么办 好动症的孩子该怎么办 18个月宝宝腹泻怎么办 8个月小孩发烧怎么办 八个月大宝宝发烧怎么办 8个月宝宝拉稀水怎么办 八个月宝宝38度怎么办 8个月的宝宝发烧怎么办 八个月大的宝宝拉肚子怎么办 9孩子上课坐不住怎么办 3岁宝宝太皮怎么办 4岁的宝宝多动症怎么办 小孩好动注意力不集中怎么办 乐扣加热变形了怎么办 3岁宝宝咳嗽厉害怎么办