为什么相同含义的代码 用c++可以过 用c语言写的就不能过

P1563 [NOIP2016 提高组] 玩具谜题

注释掉的是c语言的代码
by LuShangWu @ 2023-04-13 20:16:31


```python def isChar(c): if c>='a' and c<='z': return True else: return False def isDigit(n): if n>='0' and n<='9': return True else: return False def show(string,p1,p2,p3): flag = 0 # 用于标识-是否需要去除 1 为是 for i in range(len(string)-2): temp = string[i] temp1 = string[i+1] if(temp1=='-'): temp2 = string[i+2] if temp<temp2 and ((isChar(temp) and isChar(temp2))or (isDigit(temp) and isDigit(temp2))): flag = 1 if(p1==1): if(p3==1): print(temp,end='') for i in range(1,ord(temp2)-ord(temp)): if print(chr(i+ord(temp))*p2,end='') else: for i in range(0,ord(temp2)-ord(temp)-1): print(char(ord(temp2-i))*p2,end='') print(temp,end='') if (p1==2): else: print(temp,end='') else: if(temp=='-' and flag==0 or temp!='-'): print(f"{temp}",end='') flag = 0 print(string[len(string)-2],end='') print(string[len(string)-1],end='') p = input() p = p.split() p1 = int(p[0]) p2 = int(p[1]) p3 = int(p[2]) string = input() show(string,p1,p2,p3) ```
by LuShangWu @ 2024-04-18 09:22:55


p1==2 时存在异常 实例2异常
by LuShangWu @ 2024-04-18 09:30:26


|