既然是回文所以只要记录一半就可以了
对。11楼说的对。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Reverse(char* buf)
{
int i,len = strlen(buf);
char ch;
for(i = 0;i<len/2;i++)
{
ch = buf[i];
buf[i] = buf[len-i-1];
buf[len-i-1] = ch;
}
}
int main()
{
int index,num,temp;
char buf[50];
while(scanf("%d",&index) && index)
{
if(index > 108)
{
num = index-99;
_itoa(num,buf,10);
Reverse(buf);
printf("%d%s\n",num,buf);
}
else
{
if(index<10)
printf("%d\n",index);
else if(index<19)
printf("%d%d\n",index-9,index-9);
else
{
index-=19;
num = index/10+1;
temp = index%10;
printf("%d%d%d\n",num,temp,num);
}
}
}
return 0;
}
[此贴子已经被作者于2007-5-20 9:13:29编辑过]
对。11楼说的对。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Reverse(char* buf)
{
int i,len = strlen(buf);
char ch;
for(i = 0;i<len/2;i++)
{
ch = buf[i];
buf[i] = buf[len-i-1];
buf[len-i-1] = ch;
}
}
int main()
{
int index,num,temp;
char buf[50];
while(scanf("%d",&index) && index)
{
if(index > 108)
{
num = index-99;
_itoa(num,buf,10);
Reverse(buf);
printf("%d%s\n",num,buf);
}
else
{
if(index<10)
printf("%d\n",index);
else if(index<19)
printf("%d%d\n",index-9,index-9);
else
{
index-=19;
num = index/10+1;
temp = index%10;
printf("%d%d%d\n",num,temp,num);
}
}
}
return 0;
}
答案不正确.样例输出都没有对.思路不对.不知道你是不是把题目看错了
我没有看错题阿
因为我是用vc写的,itoa不是c标准所以出错,所以我改了,可又出来,Wrong Answer
我现在还不知哪错了呢。奇怪
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void intToStr(int num,char* buf)
{
int i,k = 0;
while(num>0)
{
i = num%10;
num/=10;
buf[k++] = i+48;
}
buf[k] = '\0';
}
int main()
{
int index,num,temp;
char buf[50];
while(scanf("%d",&index) && index!=0)
{
if(index > 108)
{
num = index-99;
intToStr(num,buf);
printf("%d%s\n",num,buf);
}
else
{
if(index<10)
printf("%d\n",index);
else if(index<19)
printf("%d%d\n",index-9,index-9);
else
{
index-=19;
num = index/10+1;
temp = index%10;
printf("%d%d%d\n",num,temp,num);
}
}
}
return 0;
}