3 条题解
-
2
方案一,按表格模拟
#include <bits/stdc++.h> int main(){ std::string s,ans; std::cin>>s; while(s.length()%3)s='0'+s; for(int i=0;i<s.length();i+=3){ if(s[i]=='0'&&s[i+1]=='0'&&s[i+2]=='0')std::cout<<0; else if(s[i]=='0'&&s[i+1]=='0'&&s[i+2]=='1')std::cout<<1; else if(s[i]=='0'&&s[i+1]=='1'&&s[i+2]=='0')std::cout<<2; else if(s[i]=='0'&&s[i+1]=='1'&&s[i+2]=='1')std::cout<<3; else if(s[i]=='1'&&s[i+1]=='0'&&s[i+2]=='0')std::cout<<4; else if(s[i]=='1'&&s[i+1]=='0'&&s[i+2]=='1')std::cout<<5; else if(s[i]=='1'&&s[i+1]=='1'&&s[i+2]=='0')std::cout<<6; else if(s[i]=='1'&&s[i+1]=='1'&&s[i+2]=='1')std::cout<<7;} return 0;}
方案二,纯计算
#include <iostream> #include <string> int twoN(int n){ int a=1; for(int i=0;i<n;i++)a*=2; return a;} int main(){ short a[105]={};std::string s; std::cin>>s; while(s.length()%3)s='0'+s; for(int i=0;i<s.length();i++) if(s[i]=='1')a[i/3]+=twoN(2-i%3); for(int i=0;i<s.length()/3;i++)std::cout<<a[i]; return 0;}
-
0
#include<iostream> using namespace std; string s,ans; int main() { cin>>s; while(s.length()%3)s='0'+s; for(int i=0;i<s.length();i+=1) { if(i%3!=2)continue; if(s[i-2]=='0'&&s[i-1]=='0'&&s[i]=='0')cout<<0; if(s[i-2]=='0'&&s[i-1]=='0'&&s[i]=='1')cout<<1; if(s[i-2]=='0'&&s[i-1]=='1'&&s[i]=='0')cout<<2; if(s[i-2]=='0'&&s[i-1]=='1'&&s[i]=='1')cout<<3; if(s[i-2]=='1'&&s[i-1]=='0'&&s[i]=='0')cout<<4; if(s[i-2]=='1'&&s[i-1]=='0'&&s[i]=='1')cout<<5; if(s[i-2]=='1'&&s[i-1]=='1'&&s[i]=='0')cout<<6; if(s[i-2]=='1'&&s[i-1]=='1'&&s[i]=='1')cout<<7; } cout<<ans; }
- 1
信息
- ID
- 532
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 1123
- 已通过
- 372
- 上传者