超级暴龙战士


私信TA

用户名:dotcpp0728507

访问量:79

签 名:

等  级
排  名 2575
经  验 2150
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 广州工商学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<iostream>

#include<stdlib.h>

#include<math.h>

using namespace std;

int main()

{

int g;

scanf("%d",&g);

getchar();

for(int w=0;w<g;w++)

{

//输入数字 

string n;

cin>>n;

getchar();

//定义字母 代表的数字

//这里用ascll来解决代表的字数

int *s=NULL,Ls=0; 

for(int i=0;i<n.size();i++)

{

for(int w=1;w<=26;w++)

if(n[i]==97-1+w)

//将他们转化为数字后拼凑在一起即可 

//用ascll来写,会遇到无法存储两位数的问题 

{

Ls++;

s=(int *)realloc(s,Ls*sizeof(int));

s[Ls-1]=pow(w,2);

break; 

}

}

//还原(需要用一个数组来还原多位数的ascll码

string temp;

temp="\0";

for(int i=0;i<Ls;i++) 

{

int *t=NULL,Lt=0;

if(s[i]<10)

{

Lt++;

t=(int *)realloc(t,Lt*sizeof(int));

t[Lt-1]=s[i]; 

}

else

{

while(s[i]!=0)

{

Lt++;

t=(int *)realloc(t,Lt*sizeof(int));

t[Lt-1]=s[i]%10;

s[i]=s[i]/10;

}

}

//

string *u=new string[Lt];

for(int w=0;w<Lt;w++)

{

u[w]=t[w]+'0';

}

for(int j=Lt-1;j>=0;j--)

{

temp=temp+u[j];

}

}

//temp去除就好了

int Lo=temp.size();

//需要重新拆成数组

int *num=(int *)malloc(Lo*sizeof(int));

for(int i=0;i<Lo;i++)

{

num[i]=temp[i]-'0';

//rp值 

int *o=(int *)malloc(Lo*sizeof(int));

int chushu=101;

int q=0;

for(int j=0;j<Lo;j++)

{

o[j]=num[j]/chushu;

q=num[j]-o[j]*chushu;

if(j!=Lo-1)

num[j+1]=q*10+num[j+1];

}

printf("%d\n",q); 

  }



}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区