全国高校绿色计算大赛 预赛第一阶段(C++)第1关:将字符串反转
2024-10-09 17:19:02
挑战任务
将输入的字符串str
进行反转。
编程要求
补全右侧vector<char> inversion(string str)
函数实现字符串的反转并返回反转之后的字符串,其中函数参数str
表示要反转的字符串。
测试说明
输入:
hello world
输出:
dlrow olleh
#ifndef _TEST
#define _TEST
#include <iostream>
#include <vector>
using namespace std; class Task{
public:
vector<char> inversion(string str){
vector <char> vec;
int index = str.length();
while(index--){
vec.push_back(str[index]);
}
return vec;
}
};
#endif
include <iostream>
#include <vector>
#include <stdio.h>
#include "Task.hpp" using namespace std; int main(){
string str;
getline(cin,str); Task tt;
vector <char> result;
result = tt.inversion(str);
for(int i = 0; i<str.length();i++){
cout << result[i];
}
cout << endl;
}
#ifndef _TEST
#define _TEST
#include <iostream>
#include <vector>
using namespace std; class Task{
public:
vector<char> inversion(string str){
vector <char> vec;
int index = str.length();
while(index--){
vec.push_back(str[index]);
}
return vec;
}
};
#endif
运行结果
最新文章
- jQuery Ajax传递数组到asp.net web api参数为空
- 【转】运行java -version命令时出现错误及解决
- 转:MFC之COleVariant
- javascript提高篇+吐槽
- R语言分析(一)-----基本语法
- java原生实现屏幕设备遍历和屏幕采集(捕获)等功能
- php 守护进程类
- 关机,重启BAT命令
- vim编辑器的设置
- java开学考试有感以及源码
- NVIDIA 驱动安装(超详细)
- 自学Python3.5-字符串格式化 作用域 递归
- Hive QL的操作
- Delphi2010如何获取程序内部自身版本号?
- [C#]记一次解析XML转对象的笔记
- mahout 使用
- 《C陷阱与缺陷》阅读笔记(个人版)
- java 大文件上传 断点续传 完整版实例 (Socket、IO流)
- 应用程序添加角标和tabBar添加角标,以及后台运行时显示
- dos系统下的游戏~ 不断更新中