NC14513. A+B
描述
小H最近刚刚学完电工电子,大作业是设计并制作一个带有显示器的加法器,由于小H比较懒,所以只设计了个位加法器。加法器在显示屏的显示效果如下图。
现在给出A,B( 0<=A,B<=9),计算出A+B的值并且用输入的样式输出结果。
输入描述
第一行一个数字T,表示T组数据,接下来输入T组数据,每组两个“数字”A,B;
输出描述
对于每组样例,按照输入样式输出其结果。(注意,每组输出结果后有一个换行)
示例1
输入:
2 *...*.***** *...*.*...* *...*.*...* *****.*...* ....*.*...* ....*.*...* ....*.***** *****.***** *...*.*...* *...*.*...* *****.***** ....*.*...* ....*.*...* *****.*****
输出:
*...* *...* *...* ***** ....* ....* ....* ....*.***** ....*.....* ....*.....* ....*.....* ....*.....* ....*.....*
C(clang 3.9) 解法, 执行用时: 3ms, 内存消耗: 364K, 提交时间: 2019-02-28 11:47:37
#include<stdio.h> #include<string.h> char s[10][70]={"******...**...**...**...**...******","....*....*....*....*....*....*....*", "*****....*....*******....*....*****","*****....*....******....*....******", "*...**...**...******....*....*....*","******....*....*****....*....******", "******....*....******...**...******","*****....*....*....*....*....*....*", "******...**...*******...**...******","******...**...******....*....******"}; char s1[100],s2[100],s3[100][100]; int len,len2,i,n,t,j,k,t1,t2,t3,ans,b,c,d; int main() { j=1; while(~scanf("%d",&t)) { while(t--) { for(i=0;i<7;i++) { scanf("%s",s3[i]); } for(i=0;i<7;i++) { for(j=0;j<=10;j++) { if(j<5) s1[i*5+j]=s3[i][j]; if(j>5) s2[i*5+j-6]=s3[i][j]; } } s1[35]='\0'; s2[35]='\0'; for(i=0;i<=9;i++) { if(strcmp(s1,s[i])==0) t1=i; if(strcmp(s2,s[i])==0) t2=i; } ans=t1+t2; if(ans<=9) { for(i=0;i<35;i++) { printf("%c",s[ans][i]); if((i+1)%5==0) printf("\n"); } } else { t2=ans%10; t1=ans/10%10; for(i=0;i<35;i++) { printf("%c",s[t1][i]); if((i+1)%5==0) { printf("."); for(j=4;j>=0;j--) { printf("%c",s[t2][i-j]); } printf("\n"); } } } printf("\n"); } } return 0; }
Java(javac 1.8) 解法, 执行用时: 189ms, 内存消耗: 13652K, 提交时间: 2020-04-22 13:17:32
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner (System.in); String a[]={"******...**...**...**...**...******", "....*....*....*....*....*....*....*", "*****....*....*******....*....*****", "*****....*....******....*....******", "*...**...**...******....*....*....*", "******....*....*****....*....******", "******....*....******...**...******", "*****....*....*....*....*....*....*", "******...**...*******...**...******", "******...**...******....*....******", }; while (in.hasNext()) { int n=in.nextInt(); while (n--!=0) { String x="",y=""; for (int i=0;i<7;i++) { String m=in.next(); x=x+m.substring(0, 5); y=y+m.substring(6,11); } int sz1=0,sz2=0,sum=0; for (int i=0;i<a.length;i++) { if (x.equals(a[i]))sz1=i; if (y.equals(a[i]))sz2=i; } sum=sz1+sz2; if (sum/10==0) { int index=0; for (int i=0;i<35;i++) { index++; if (index%5==0)System.out.println(a[sum].substring(i, i+1)); else System.out.print(a[sum].substring(i, i+1)); } } else { int shi=sum/10; int ge=sum%10; int index=0; for (int i=0;i<35;i+=5) { System.out.println(a[shi].substring(i, i+5)+"."+a[ge].substring(i,i+5)); } } System.out.println(); } } } }
C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 380K, 提交时间: 2020-07-21 20:41:45
#include<bits/stdc++.h> using namespace std; int n,dp[1201][1201]; string s; map<string,int>mp; int main(){ mp["******...**...**...**...**...******"]=0; mp["....*....*....*....*....*....*....*"]=1; mp["*****....*....*******....*....*****"]=2; mp["*****....*....******....*....******"]=3; mp["*...**...**...******....*....*....*"]=4; mp["******....*....*****....*....******"]=5; mp["******....*....******...**...******"]=6; mp["*****....*....*....*....*....*....*"]=7; mp["******...**...*******...**...******"]=8; mp["******...**...******....*....******"]=9; cin>>n; while(n--){ string s1="",s2=""; char x; for(int i=0;i<7;i++){ for(int j=0;j<11;j++){ cin>>x; if(j<5)s1+=x ; else if(j==5)continue; else s2+=x; } } int ans=mp[s1]+mp[s2]; if(ans>=10){ int ten=ans/10,ge=ans%10; string s,ss; for(std::map<string ,int>::iterator it = mp.begin();it!=mp.end();it++){ if(it->second==ten) s=it->first; if(it->second==ge) ss=it->first; } for(int i=0;i<7;i++){ string s_; s_=s.substr(i*5,5)+"."+ss.substr(i*5,5); cout<<s_<<endl; } }else{ int ge=ans; string ss; for(std::map<string ,int>::iterator it = mp.begin();it!=mp.end();it++){ if(it->second==ge) ss=it->first; } for(int i=0;i<7;i++){ string s_; s_=ss.substr(i*5,5); cout<<s_<<endl; } } cout<<endl; } }
C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 476K, 提交时间: 2019-07-28 11:42:19
#include <bits/stdc++.h> using namespace std; map <string,int> s; char z[10][100]={"******...**...**...**...**...******", "....*....*....*....*....*....*....*", "*****....*....*******....*....*****", "*****....*....******....*....******", "*...**...**...******....*....*....*", "******....*....*****....*....******", "******....*....******...**...******", "*****....*....*....*....*....*....*", "******...**...*******...**...******", "******...**...******....*....******" }; string a,b,c; #define rei register int void write(string t) { for(rei i=0;i<7;++i) { for(rei j=5*i;j<5*(i+1);++j) putchar(t[j]); putchar('\n'); } } void w1(string t1,string t2) { for(rei i=0;i<7;++i) { for(rei j=5*i;j<5*(i+1);++j) putchar(t1[j]); putchar('.'); for(rei j=5*i;j<5*(i+1);++j) putchar(t2[j]); putchar('\n'); } } void solve() { a=b=""; for(rei i=1;i<=7;++i) { cin>>c; a+=c.substr(0,5); b+=c.substr(6,5); } int ans=s[a]+s[b]; if(ans<10) write(z[ans]); else w1(z[ans/10],z[ans%10]); } int main() { for(rei i=0;i<=9;++i) s[z[i]]=i; int t;cin>>t; while(t--) { solve();putchar('\n'); } }
Python3(3.5.2) 解法, 执行用时: 17ms, 内存消耗: 3576K, 提交时间: 2020-07-21 20:09:05
a = '*'*5 + '*...*'*5 + '*'*5 b = '....*'*7 c = '*'*5 + '....*'*2 + '*'*5 + '*....'*2 + '*'*5 d = '*'*5 + '....*'*2 + '*'*5 + '....*'*2 + '*'*5 e = '*...*'*3 + '*'*5 + '....*'*3 f = '*'*5 + '*....'*2 + '*'*5 + '....*'*2 + '*'*5 g = '*'*5 + '*....'*2 + '*'*5 + '*...*'*2 + '*'*5 h = '*'*5 + '....*'*6 i = '*'*5 + '*...*'*2 + '*'*5 + '*...*'*2 + '*'*5 j = '*'*5 + '*...*'*2 + '*'*5 + '....*'*2 + '*'*5 dic1 = {a:0,b:1,c:2,d:3,e:4,f:5,g:6,h:7,i:8,j:9} dic2 = {0:a,1:b,2:c,3:d,4:e,5:f,6:g,7:h,8:i,9:j} anses = [] for _ in range(int(input())): a='' b='' if _ > 0: x= input() for i in range(7): temp = input() a+=temp[0:5] b+=temp[6:] ans = dic1[a] + dic1[b] anses.append(ans) for each in anses: if each < 10: for i in range(1,8): print(dic2[each][(i-1)*5:i*5]) else: for i in range(1,8): print(dic2[1][(i-1)*5:i*5] + '.' + dic2[each-10][(i-1)*5:i*5]) print('')