85pts 球条
查看原帖
85pts 球条
551788
Miyamizu_Mitsuha楼主2023/9/9 10:55

感觉是判error有问题。但是也没检查出来

#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
  int lll=1;
  char a[100005];
  while(cin>>a[lll])
  {
    if(a[lll]!='0'&&a[lll]!='1')
    {cout<<"Error";return 0;}
    lll++;
  }
  lll--;
  if(lll%8!=0) {cout<<"Error";return 0;}
  int hhs=lll/8;
  int bj=0,pre=0;
  for(int i=1;i<=hhs;i++)
  {
    int top=8*(i-1)+1;
    if(a[top]=='1'&&a[top+1]=='1'&&a[top+2]=='1')
    {
      cout<<' ';
      continue;
    }
    else if(a[top]=='1'&&a[top+1]=='0'&&a[top+2]=='1')
    {
      int q=(a[top+3]-'0')*16+(a[top+4]-'0')*8+(a[top+5]-'0')*4+(a[top+6]-'0')*2+(a[top+7]-'0')*1;
      if(q>25)
      {
        cout<<"Error";
        return 0;
      }else 
      {
      cout<<(char)((a[top+3]-'0')*16+(a[top+4]-'0')*8+(a[top+5]-'0')*4+(a[top+6]-'0')*2+(a[top+7]-'0')*1+'A');
      continue;
      }
    }
     else if(a[top]=='0')
    {
      if(bj==1){
       cout<<pre+((a[top+1]-'0')*64+(a[top+2]-'0')*32+(a[top+3]-'0')*16+(a[top+4]-'0')*8+(a[top+5]-'0')*4+(a[top+6]-'0')*2+(a[top+7]-'0')*1)/2;
       pre=0;
       bj=0;
       continue;
      }
      if(bj==0)
      {
        pre=((a[top+1]-'0')*64+(a[top+2]-'0')*32+(a[top+3]-'0')*16+(a[top+4]-'0')*8+(a[top+5]-'0')*4+(a[top+6]-'0')*2+(a[top+7]-'0')*1)/2;
        bj=1;
        continue;
      }
     
    }else 
    {
      cout<<"Error";
      return 0;
    }
  }

  
  
return 0;
}

2023/9/9 10:55
加载中...