更小的数

题目描述

https://www.dotcpp.com/oj/problem3143.html

代码

#include<iostream>
using namespace std;
 
bool isfan(string& nums, int j, int i){
    while(i < j){
        if(nums[i] > nums[j]){
            return true ;
        }else if(nums[i] < nums [j]){
            return false ;
        }
        i++;
        j--;
    }
    return false ;
}
 
int getanswer(string& nums, int size){
    int result = 0;
    for(int i = 0; i < size; i++){
        for(int j = 0; j < i; j++){
            if(isfan(nums, i ,j)){
                result++ ;
            }
        }
    }
    return result;
}
 
 
int main(){
    string nums;
    cin>>nums;
    cout << getanswer(nums, nums.size());
    return 0;
}
posted @ 2023-08-10 17:18  铜锣湾陈昊男  阅读(9)  评论(0)    收藏  举报