[問題] ltoa的使用
遇到的問題: (題意請描述清楚)
在寫ACM 10018,自己run可以,但上傳後顯示Compilation error
自己用g++要編譯,也顯示: error: 'ltoa' was not declared in this scope
程式跑出來的錯誤結果:
error: 'ltoa' was not declared in this scope
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
用Code::Blocks可以編譯,但g++和acm 都不給過
有問題的code: (請善用置底文標色功能)
#include <iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
int j,n,reverse,count,add;
char str[999],tmp[999],sadd[999];
bool ispalindrome=false;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
ispalindrome=false;
count=0;
scanf("%s",str);
while(!ispalindrome)
{
for(j=strlen(str)-1;j>=0;j--)
{
tmp[strlen(str)-j-1]=str[j];
}
tmp[strlen(str)-j-1]='\0';
reverse=atoi(tmp);
if(reverse==atoi(str))
{
ispalindrome=true;
break;
}
add=reverse+atoi(str);
count++;
ltoa(add,sadd,10);
strncpy(str,sadd,sizeof(sadd));
}
printf("%d %s\n",count,str);
}
return 0;
}
補充說明:
去cppreference好像只有atoi,沒有ltoa
那請問現在比較好的"整數轉字串"是什麼方法呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.230.240
→
11/18 23:55, , 1F
11/18 23:55, 1F
推
11/18 23:56, , 2F
11/18 23:56, 2F
→
11/19 00:01, , 3F
11/19 00:01, 3F
→
11/19 00:01, , 4F
11/19 00:01, 4F
→
11/19 11:16, , 5F
11/19 11:16, 5F
→
11/20 09:55, , 6F
11/20 09:55, 6F