写在前面
今天笔试中有一个题目,要求将单词翻转,例如"hx hell1 liwe! asfd",根据空格来划分单词,如果单词中存在非字母,则原样输出,否则翻转输出(不能使用函数库函数)
程序
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 205;
void _swap(char* a,char* b)
{
char tmp=*a; *a = *b; *b = tmp;
}
bool Judge(const char* s,int len)
{
for(int i =0 ;i < len;i ++)
if((*(s+i) >= 'a' && *(s+i) <= 'z' ) || ((*s+i) >= 'A' && (*s+i) <= 'Z'))
continue;
else
return false;
return true;
}
bool _reverse(void* first,void* l