[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
感谢楼上分享, 我用ai改powershell, 几十轮都不行? 哎, ai还是不行啊
  1. function Convert-RMB {
  2.     param (
  3.         [string]$input
  4.     )
  5.    
  6.     # 检查输入是否为数字
  7.     if (-not ($input -match '^[0-9]*$')) {
  8.         Write-Host "非法输入!"
  9.         return
  10.     }
  11.     $units = @('圆', '拾', '佰', '仟', '萬', '拾萬', '佰萬', '仟萬', '亿', '拾亿', '佰亿', '仟亿', '兆', '拾兆', '佰兆', '仟兆', '京', '拾京', '佰京', '仟京', '垓', '拾垓', '佰垓', '仟垓', '秭', '拾秭', '佰秭', '仟秭', '穰', '拾穰', '佰穰', '仟穰', '沟', '拾沟', '佰沟', '仟沟', '涧', '拾涧', '佰涧', '仟涧', '正', '拾正', '佰正', '仟正', '载', '拾载', '佰载', '仟载', '极')
  12.     $digits = @('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖')
  13.    
  14.     # 计算输入的长度
  15.     $length = $input.Length
  16.     $result = ""
  17.     for ($i = 0; $i -lt $length; $i++) {
  18.         $digit = [int]$input[$i]
  19.         $position = $length - $i - 1
  20.         $unit = if ($position -lt $units.Length) { $units[$position] } else { "" }
  21.         if ($digit -ne 0) {
  22.             $result += $digits[$digit] + $unit
  23.         } elseif ($unit -match '圆|萬|亿|兆|京|垓|秭|穰|沟|涧|正|载|极') {
  24.             $result += $unit
  25.         } elseif ($result -ne "" -and $result[-1] -ne '零') {
  26.             $result += '零'
  27.         }
  28.     }
  29.     $result = $result -replace '零+', '零'
  30.     $result = $result -replace '零$', ''
  31.     $result = $result -replace '零圆$', '圆'
  32.     return $result
  33. }
  34. # 测试
  35. $input = Read-Host "输入一个数字"
  36. $result = Convert-RMB -input $input
  37. Write-Host "输入:" $input
  38. Write-Host "输出:" $result
复制代码

TOP

返回列表