题解 | #翻转链表#
翻转链表
https://www.nowcoder.com/practice/f350f14cd22c41aabfa7e54a1b8e8825
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
//解析字符串为整数向量
vector<int> parseCSV(string& input) {
vector<int> numbers;
stringstream ss(input);
string token;
while (getline(ss, token, ',')) {
// 将token转换为整数并添加到数组
numbers.push_back(stoi(token));
}
return numbers;
}
int main()
{
string s; //作为字符串接受后解析数据
vector<int> nums;
while (cin >> s)
{
nums = parseCSV(s);
int i,j=0;
i=nums.size();
for(j=0 ; j<=i/2-1 ; j++)
{
cout << nums[j] <<","<<nums[i-j-1];
if(j!=i/2-1) cout<<",";
}
if( i%2==1&& i!=1) cout <<","<< nums[i/2];
else if(i%2==1) cout << nums[i/2];
}
}
// 64 位输出请用 printf("%lld")
