cheng_you_know

学而时习之!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#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\n%s\n",s3);
        }
        else
        {
            printf("No\n%s\n",s3);
        }
        
    }
    return 0;
}
posted on 2014-01-21 21:16  cheng_you_know  阅读(179)  评论(0编辑  收藏  举报