zju pat 1023 Have Fun with Numbers

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
char s1[30];
char s2[30];
char s3[30];
char *reverse(char *s)
{
    if(s==NULL)
        return NULL;
    int end = strlen(s) -1;
    int begin = 0;
    char temp;
    while(begin <= end)
    {
        temp = s[begin];
        s[begin] = s[end];
        s[end] = temp;
        begin++;
        end --;
    }
    return s;
}
int main()
{
    int i,j,k,len1,temp,len2;
    while(scanf("%s",s1)!=EOF)
    {
        memset(s2,0,sizeof(s2));
        len1 = strlen(s1);
        k = 0;
        for(i =len1-1;i>=0;i--)
        {
            temp = (s1[i]-'0') * 2 ;
            s2[k++] += temp % 10;
            s2[k]+= temp/10;
        }
        if(s2[k]!=0)
        {
            s2[k+1] = 0;
            k++;
        }
        for(i =0; i<k;i++)
        {
            s2[i]+='0';  //加上'0',转到数字字符
        }
        reverse(s2);
        strcpy(s3,s2);
        sort(s1,s1+strlen(s1));  //按字典序排序,然后对比看看是不是原来的全排列
        sort(s2,s2+strlen(s2));
        if(strcmp(s1,s2)==0)
        {
            printf("Yes
%s
",s3);
        }
        else
        {
            printf("No
%s
",s3);
        }
        
    }
    return 0;
}
原文地址:https://www.cnblogs.com/cheng07045406/p/3528886.html