蒟蒻的自我拯救。。。
#include <cstdio>
#include <cstring>
using namespace std;
char num[85];
int dp[85], n;
bool judge(int st1,int len1,int st2,int len2)
{
while (num[st1] == '0' && len1) st1++, len1--;
while (num[st2] == '0' && len2) st2++, len2--;
if (len1 < len2) return 1;
else if (len1 > len2) return 0;
else
{
for (int i = 0; i < len1; i++)
{
if (num[st1+i] < num[st2+i]) return 1;
if (num[st1+i] > num[st2+i]) return 0;
}
}
return 0;
}
void print(int pos)
{
if (pos > n) return;
if (pos != 1) printf(",");
for (int i = pos; i < pos + dp[pos]; i++)
printf("%c", num[i]);
print(pos + dp[pos]);
}
int main()
{
while (~scanf("%s", num + 1) && strcmp(num + 1, "0"))
{
n = strlen(num + 1);
dp[1] = 1;
for (int i = 2; i <= n; i++)
{
dp[i] = i;
for (int j = i - 1; j >= 1; j--)
if (judge(j - dp[j] + 1, dp[j], j + 1, i - j))
{
dp[i] = i - j;
break;
}
}
int pos = n - dp[n] + 1;
dp[pos] = dp[n];
for (int i = pos - 1; i >= 1; i--)
{
if (num[i] == '0')
{
dp[i] = dp[i+1] + 1;
continue;
}
for (int j = pos; j > i; j--)
if (judge(i, j - i, j, dp[j]))
{
dp[i] = j - i;
break;
}
}
print(1);
printf("\n");
}
return 0;
}