Advertisement

华为OD机试试题 C++ 火星文计算(Q4)100分

阅读量:

**■**题目描述

复制代码
 #include <bits/stdc++.h>

    
  
    
 using namespace std;
    
  
    
 int MarsCharacters(string str) 
    
 {
    
     int index = str.find_last_of("#");
    
     if (index != str.npos) {
    
     string left = str.substr(0, index);
    
     string right = str.substr(index + 1);
    
     int res = 2 * MarsCharacters(left) + 3 * MarsCharacters(right) + 4;
    
     return res;
    
     }
    
     index = str.find_last_of("$");
    
     if (index != str.npos) {
    
     string left = str.substr(0, index);
    
     string right = str.substr(index + 1);
    

全部评论 (0)

还没有任何评论哟~