使用c 语言实现输入任意一行字符(如:abcd), 并按反序输出(如:dcba)
string getReverse(string input){
string answer="";
int i;
for(i=input.length()-1;i>=0;i--)
answer=answer input[i];
return answer;
}
int main(){
vector<string> question;
vector<string> answer;
string temp;
int i;
while(getline(cin,temp))
question.push_back(temp);
for(i=0;i<question.size();i )
{
temp=getReverse(question[i]);
answer.push_back(temp);
}
for(i=0;i<answer.size();i )
cout<<answer[i]<<endl;
return 0;
}
评论