编程:将给定字符串中的数字逆序,比如 abc2319bcj453 逆序后为 abc3549bcj132
思路:
(1)双指针
(2)栈
#include "stdio.h"
#include <iostream>
#include <string>
#include <stack>
#include <memory>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
static void reverseIntStr(string inputStr);
/*编程:将给定字符串中的数字逆序,比如 abc2319bcj453 逆序后为 abc3549bcj132*/
bool isDigit(char c) {
return c>'0'&&c<'9';
}
void reverseIntStr(string inputStr){
cout<<"input:"<<inputStr<<endl;
int m = inputStr.size()-1;
string rtnStr="";
stack<char> intStack;
//移除末尾空格
while (inputStr[m]==' ')
{
m--;
}
for(auto c: inputStr ) {
if( isDigit(c) ) {
intStack.push(c);
}
}
for(auto c: inputStr ) {
char tmp=c;
if( isDigit(c) && !intStack.empty() ) {
tmp = intStack.top();
intStack.pop();
cout<<"push:"<<tmp<<endl;
}
rtnStr+=tmp;
}
cout<<"Result:"<<rtnStr;
}
int main(){
printf("hello world!");
reverseIntStr(string("abc2319bcj453"));
return 0;
}
1.如何实现下采样?他们的区别是什么?
下采样(downscaling)或缩小图像尺寸是计算机视觉和图像处理中的常见任务,旨在减少图像的像素尺寸,同时尽量保持其视觉质量。以下是一些常见的下采样算法:
-
最近邻采样 (Nearest Neighbor Interpolation): 这是最简单的下采样方法,通过直接复制最近的像素值到新位