题目:
代码实现【这个代码在vc上运行正常,但在oj平台上总提示格式错误,郁闷!!!!】:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
int Reserve(char *str);
char str1[100];
cin>>str1;
Reserve(str1);
cout<<endl<<str1;
return 0;
}
int Reserve(char *str)
{
int len=strlen(str);
char *begin,*end;
begin = str;
end = str+len-1;
char temp;
if(str!=NULL)
{
while(begin<end)
{
temp=*begin;
*begin=*end;
*end=temp;
begin++;
end--;
}
}
return 0;
}
代码评价:上述代码
在vc上运行正常,但在oj平台上总提示格式错误,得分20分(满分100),找不到解决办法。
后来在评价上,看到别人评论的一串代码,试了试oj平台正确通过了:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string StrIn;
int i;
getline(cin,StrIn);
for(i=StrIn.length()-1;i>=0;i--)
{
cout<<StrIn[i];
}
return 0;
}