3 条题解

  • 2
    @ 2023-10-28 15:01:16

    方案一,按表格模拟

    #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
      @ 2023-12-9 20:40:00
      #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;
      }
      
      • 0
        @ 2023-11-5 18:38:11

        三位一截断,计算三位内的值

        #include<bits/stdc++.h>
        using namespace std;
        
        int main(){
        	string s,ans;
        	cin>>s;
        	int ls=s.size(),tmp=0;
        	for(int i=ls-1;i>=0;i--){
        		tmp=tmp+(s[i]-'0')*pow(2,(ls-1-i)%3);
        		if((ls-1-i)%3==2 || i==0){
        			ans=char(tmp+'0')+ans;
        			tmp=0;
        		}
        	}
        	cout<<ans;
        	return 0;
        }
        
        • 1

        信息

        ID
        532
        时间
        1000ms
        内存
        256MiB
        难度
        6
        标签
        递交数
        1123
        已通过
        372
        上传者