NC223556. MethodicMultiplication
描述
输入描述
The input consists of two lines. Each line contains a natural number defined in Peano arithmatic, using at most 1000 characters.
输出描述
Output the product of the two input numbers.
示例1
输入:
S(S(0)) S(S(S(0)))
输出:
S(S(S(S(S(S(0))))))
示例2
输入:
S(S(S(S(S(0))))) 0
输出:
0
C++ 解法, 执行用时: 9ms, 内存消耗: 768K, 提交时间: 2021-08-12 14:48:23
#include<bits/stdc++.h> using namespace std; int main() { char s1[1001],s2[1001]; cin>>s1>>s2; int a=(strlen(s1)-1)/3,b=(strlen(s2)-1)/3,c=a*b; for(int i=0;i<c;++i) cout<<"S("; cout<<0; for(int i=0;i<c;++i) cout<<')'; return 0; }
Python3 解法, 执行用时: 50ms, 内存消耗: 7040K, 提交时间: 2021-08-03 13:23:48
a=input().count("S") b=input().count("S") ans=a*b if(ans==0): print(0) else: print("S("*ans+'0'+')'*ans)