Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
BasisTest.cpp 29.14 KB
Copy Edit Web IDE Raw Blame History
fudum authored 2014-07-14 15:24 . 添加自守数,链表查询等函数
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
#include "stdafx.h"
#include "BasisTest.h"
#include <math.h>
#include <string>
#include <iostream>
#include <map>
#include <list>
#include <vector>
std::map<int,std::string> BasisTest::mE;
std::map<int,std::string> BasisTest::mY;
BasisTest::BasisTest(void)
{
}
BasisTest::~BasisTest(void)
{
}
void BasisTest::theLastWord()
{
int lastSize = 0;
std::string inputStr;
getline(std::cin,inputStr);
while (inputStr.size() >= 128 || inputStr.size() == 0)
{
std::cout<<"please input the size < 128 && size > 0"<<std::endl;
std::cin>>inputStr;
}
//字符串长度为1
if (inputStr.size() == 1)
{
if (inputStr.at(0) == ' ')
{
lastSize = 0;
}
else
{
lastSize = 1;
}
}
else
{
int endNum = 0;
int startNum = 0;
for (int i = inputStr.size() - 1; i >=0; i--)
{
if (inputStr.at(i) != ' ' )
{
endNum = i;
break;
}
}
for (int i = endNum; i >=0; i--)
{
if (inputStr.at(i) == ' ' )
{
startNum = i;
break;
}
}
lastSize = endNum - startNum;
}
std::cout<<lastSize<<std::endl;
}
int BasisTest::pictureTrim()
{
int len;
char str[1024];
gets_s(str);
len=strlen(str);
//对输入的条件进行判断
//如果为产度为0
if (len==0)
{
return 0;
}
//如果长度大于1024
if (len > 1024)
{
return -1;
}
//如果输入的不符合要求
for (int i = 0; i < len; i++)
{
if (!((str[i] <= 'Z' && str[i] >='A') || (str[i] <='z' && str[i] >='a') || (str[i] >='0' && str[i] <='9')))
{
return -1;
}
}
char tmp;
//这个排序可以优化
for (int i = 0; i < len; i++)
{
for (int j = i+1; j < len; j++)
{
if (str[j] < str[i])
{
tmp = str[j];
str[j] = str[i];
str[i] = tmp;
}
}
}
printf("%s",str);
return 0;
}
int BasisTest::shuzidiandao()
{
int len;
char retVal[128];
char str[128];
gets_s(str);
len=strlen(str);
if (len == 0)
{
return 0;
}
if (len > 128)
{
return -1;
}
int j = 0;
for (int i = len -1; i >=0; i --)
{
retVal[j] = str[i];
j++;
}
retVal[j] = '\0';
printf("%s",retVal);
return 0;
}
int BasisTest::zifugeshu()
{
int retNum = 0;
int len;
char str[128];
gets_s(str);
char tmp;
tmp = getchar();
len=strlen(str);
if (len == 0)
{
return 0;
}
for (int i = 0; i < len; i++)
{
if (str[i] <='Z' && str[i] >='A')
{
if (str[i] == tmp || str[i] + 32 == tmp )
{
retNum++;
}
}
else if (str[i] <='z' && str[i] >= 'a')
{
if (str[i] == tmp || str[i] - 32 == tmp )
{
retNum++;
}
}
else if (str[i] == tmp)
{
retNum++;
}
}
printf("%d",retNum);
return 0;
}
bool BasisTest::IsAllCharExist(char* pShortString,char* pLongString)
{
bool retVal = true;
int slen = strlen(pShortString);
int llen = strlen(pLongString);
if (slen == 0 || llen == 0)
{
retVal = false;
}
if (slen > llen)
{
retVal = false;
}
else if (slen == llen)
{
for (int i = 0; i < slen; i++)
{
if (pShortString[i] != pLongString[i])
{
retVal = false;
break;
}
}
}
else
{
for (int i = 0; i < llen - slen; i++)
{
for (int j = 0; j < slen; j++)
{
if (pShortString[j] != pLongString[i+j])
{
retVal = false;
break;
}
}
}
}
return retVal;
}
std::string BasisTest::MarkNum(std::string pInStr)
{
std::string retVal;
if (pInStr.size() == 0)
{
}
else if (pInStr.size() == 1)
{
if (pInStr[0] <= '9' && pInStr[0] >= '0')
{
retVal.append("*");
retVal.append(pInStr);
retVal.append("*");
}
else
{
retVal.append(pInStr);
}
}
else
{
int len = pInStr.size();
if (pInStr[0] >='0' && pInStr[0] <='9')
{
retVal.append("*");
retVal.append(pInStr.substr(0,1));
}
else
{
retVal.append(pInStr.substr(0,1));
}
for (int i = 1; i < len; i++)
{
if ((pInStr[i] >= '0' && pInStr[i] <= '9') && (pInStr[i-1] > '9' || pInStr[i-1] <'0'))
{
retVal.append("*");
retVal.append(pInStr.substr(i,1));
}
else if ((pInStr[i] <= '9' && pInStr[i] >= '0') && (pInStr[i - 1] >= '0' && pInStr[i-1] <= '9'))
{
retVal.append(pInStr.substr(i,1));
}
else if ((pInStr[i] > '9' || pInStr[i] < '0') && (pInStr[i - 1] >= '0' && pInStr[i-1] <= '9'))
{
retVal.append("*");
retVal.append(pInStr.substr(i,1));
}
else if ((pInStr[i] > '9' || pInStr[i] < '0') && (pInStr[i - 1] < '0' || pInStr[i-1] > '9'))
{
retVal.append(pInStr.substr(i,1));
}
}
}
return retVal;
}
int BasisTest::dengchashulie()
{
int num;
int retVal = 0;
std::cin>>num;
if (num > 0)
{
retVal = (num * 2 + num*(num-1) * 3/2);
std::cout<<retVal;
}
else
{
return -1;
}
return 0;
}
int BasisTest::jinzhizhuanhuan()
{
int retVal =0;
std::string inStr;
std::cin>>inStr;
if (inStr.size() < 2)
{
return -1;
}
else if (inStr[0] != '0')
{
return -1;
}
else if (inStr[1] != 'X' && inStr[1] != 'x' )
{
return -1;
}
else
{
for (unsigned int i = 2; i < inStr.size(); i++)
{
if ((inStr[i] >='0' && inStr[i] <='9') || (inStr[i] >='a' && inStr[i] <='f') ||(inStr[i] >='A' && inStr[i] <='F'))
{
}
else
{
return -1;
}
}
int mi = 0;
int xishu = 1;
for (int i = inStr.size() -1 ; i >=2; i--)
{
if (inStr[i] <='9' && inStr[i] >='0')
{
retVal+= xishu * (int)(inStr[i] - '0');
}
else if (inStr[i] <='f' && inStr[i] >='a')
{
retVal+= xishu * ((int)(inStr[i] - 'a') +10);
}
else if (inStr[i] <='F' && inStr[i] >='A')
{
retVal+= xishu * ((int)(inStr[i] - 'A') +10);
}
mi ++;
xishu *=16;
}
std::cout<<retVal;
}
return 0;
}
int BasisTest::zifuchuannixu(void)
{
std::string retVal;
std::string inputString;
getline(std::cin,inputString);
for (int i= inputString.size() - 1; i >=0; i--)
{
retVal.append(inputString.substr(i,1));
}
std::cout<<retVal;
return 0;
}
int BasisTest::zifuchuantongji(void)
{
std::string retVal;
std::map<char,int> mapOne;
std::string inStr;
getline(std::cin,inStr);
if (inStr.size() == 0)
{
return 0;
}
else
{
for (unsigned int i = 0; i < inStr.size(); i++)
{
//首先要对字符进行判断
if ((inStr[i] >= '0' && inStr[i] <='9') || (inStr[i] >= 'a' && inStr[i] <='z') || (inStr[i] >= 'A' && inStr[i] <='Z') || (inStr[i] ==' '))
{
//如果map中没有 插入数据
if (mapOne.find(inStr[i]) == mapOne.end())
{
mapOne.insert(std::pair<char,int>(inStr[i],1));
}
else
{
mapOne.find(inStr[i])->second ++;
}
}
}
while (mapOne.size() >0)
{
std::map<char,int>::iterator the_iterator;
the_iterator = mapOne.begin();
int num = 0;
char tmp;
while(the_iterator != mapOne.end())
{
if (the_iterator->second > num)
{
tmp = the_iterator->first;
num = the_iterator->second;
}
the_iterator ++;
}
retVal.append(1,tmp);
mapOne.erase(tmp);
}
std::cout<<retVal;
}
return 0;
}
int BasisTest::baohanbutongzifugeshu(void)
{
std::map<char,int> retVal;
std::string inStr;
getline(std::cin,inStr);
for (unsigned int i = 0; i < inStr.size(); i++)
{
if (inStr[i] >= 0 && inStr[i] <= 127)
{
if (retVal.find(inStr[i]) == retVal.end())
{
retVal.insert(std::pair<char,int>(inStr[i],1));
}
}
}
std::cout<<retVal.size();
return 0;
}
int BasisTest::zuixiaogongbeishu(void)
{
int retVal = 0;
int a;
int b;
std::cin>>a;
std::cin>>b;
if (a > 0 && b>0)
{
if (a == b)
{
retVal = a;
}
else if (a > b)
{
for (int i = 1; i <= b; i++)
{
if ((a * i) % b == 0)
{
retVal = a* i;
break;
}
}
}
else
{
for (int i = 1; i <= a; i++)
{
if ((b * i) % a == 0)
{
retVal = b* i;
break;
}
}
}
std::cout<<retVal;
}
else
{
return -1;
}
return 0;
}
int BasisTest::qujinsizhi(void)
{
int retVal;
double inPara;
std::cin>>inPara;
if (std::cin.fail())
{
//如果输入失败
return -1;
}
else
{
if (inPara >= 0)
{
retVal = (int)(inPara + 0.5);
}
else
{
retVal = (int)(inPara - 0.5);
}
std::cout<<retVal;
}
return 0;
}
int BasisTest::zifuchuanfanzhuan(void)
{
std::string retVal;
std::string inPara;
getline(std::cin,inPara);
for (int i = inPara.size() -1; i >=0; i--)
{
retVal.append(1,inPara[i]);
}
std::cout<<retVal;
return 0;
}
bool BasisTest::FindChar(char* pInputString, char* pChar)
{
/*char pInputString[128];
std::cin>>pInputString;
char pChar[1];*/
int len = strlen(pInputString);
if (len == 0)
{
std::cout<<'.';
return false;
}
else if (len == 1)
{
pChar = pInputString;
std::cout<<pInputString;
return true;
}
else
{
bool flag = true;
int index = -1;
for (int i = 0; i < len -1; i++)
{
for (int j = 0; j < len; j++)
{
if (pInputString[i] == pInputString[j])
{
flag = false;
break;
}
}
if (flag == true)
{
pChar = pInputString + i;
index = i;
std::cout<<pInputString[i];
return true;
}
}
if (index == -1)
{
std::cout<<'.';
return false;
}
return true;
}
}
bool BasisTest::GetMinK(unsigned int uiInputNum, int * pInputArray, unsigned int uiK, int * pOutputArray)
{
/*unsigned int uiInputNum;
unsigned int uiK;
int pInputArray[M];
int pOutputArray[M];
std::cin>>uiInputNum;
if (std::cin.fail())
{
return -1;
}
std::cin>>uiK;
if (std::cin.fail())
{
return -1;
}
unsigned int i = 0;
while (i < uiInputNum)
{
std::cin>>pInputArray[i];
i++;
}*/
if (uiK > uiInputNum)
{
return false;
}
int index;
int tmp;
for (unsigned int i = 0; i < uiInputNum -1; i++)
{
index = i;
for (unsigned int j = i+1; j < uiInputNum; j++)
{
if (pInputArray[i] > pInputArray[j])
{
index = j;
}
}
if (index !=i)
{
tmp = pInputArray[i];
pInputArray[i] = pInputArray[index];
pInputArray[index] = tmp;
}
}
for (unsigned int i = 0; i < uiK; i++)
{
pOutputArray[i] = pInputArray[i];
std::cout<<pOutputArray[i];
if (i != (uiK -1))
{
std::cout<<' ';
}
}
return true;
}
int BasisTest::mingmingdesuijishu(void)
{
int num;
int inArr[100];
std::map<int,int> mapInt;
std::cin>>num;
if (std::cin.fail())
{
return -1;
}
int i = 0;
while (i < num)
{
std::cin>>inArr[i];
if (mapInt.find(inArr[i]) == mapInt.end())
{
mapInt.insert(std::pair<int,int>(inArr[i],0));
}
i++;
}
std::map<int,int>::iterator the_iterator;
the_iterator = mapInt.begin();
while(the_iterator != mapInt.end())
{
std::cout<<the_iterator->first<<std::endl;
the_iterator ++;
}
return 0;
}
//学英语
void BasisTest::initMap()
{
mE.insert(std::pair<int,std::string>(0,"zero"));
//one,two,three,four,five,six,seven,eight,nine,ten.
mE.insert(std::pair<int,std::string>(1,"one"));
mE.insert(std::pair<int,std::string>(2,"two"));
mE.insert(std::pair<int,std::string>(3,"three"));
mE.insert(std::pair<int,std::string>(4,"four"));
mE.insert(std::pair<int,std::string>(5,"five"));
mE.insert(std::pair<int,std::string>(6,"six"));
mE.insert(std::pair<int,std::string>(7,"seven"));
mE.insert(std::pair<int,std::string>(8,"eight"));
mE.insert(std::pair<int,std::string>(9,"nine"));
mE.insert(std::pair<int,std::string>(10,"ten"));
//eleven,twelve, thirteen, fourteen, fifteen,
//sixteen, seventeen,eighteen, nineteen.
mE.insert(std::pair<int,std::string>(11,"eleven"));
mE.insert(std::pair<int,std::string>(12,"twelve"));
mE.insert(std::pair<int,std::string>(13,"thirteen"));
mE.insert(std::pair<int,std::string>(14,"fourteen"));
mE.insert(std::pair<int,std::string>(15,"fifteen"));
mE.insert(std::pair<int,std::string>(16,"sixteen"));
mE.insert(std::pair<int,std::string>(17,"seventeen"));
mE.insert(std::pair<int,std::string>(18,"eighteen"));
mE.insert(std::pair<int,std::string>(19,"nineteen"));
// 21——99
//twenty,thirty, forty,fifty,eighty sixty,seventy,ninety
mE.insert(std::pair<int,std::string>(20,"twenty"));
mE.insert(std::pair<int,std::string>(30,"thirty"));
mE.insert(std::pair<int,std::string>(40,"forty"));
mE.insert(std::pair<int,std::string>(50,"fifty"));
mE.insert(std::pair<int,std::string>(60,"sixty"));
mE.insert(std::pair<int,std::string>(70,"seventy"));
mE.insert(std::pair<int,std::string>(80,"eighty"));
mE.insert(std::pair<int,std::string>(90,"ninety"));
//构造另外一个map
mY.insert(std::pair<int,std::string>(0,""));
mY.insert(std::pair<int,std::string>(1,"hundred"));
mY.insert(std::pair<int,std::string>(2,"thousand"));
mY.insert(std::pair<int,std::string>(3,"million"));
mY.insert(std::pair<int,std::string>(4,"billion"));
}
std::string BasisTest::parse_3(int tmp,int flag)
{
std::string retVal;
int i_3;
int i_2;
int i_1;
if (tmp > 0)
{
i_3 = tmp / 100;
if (i_3 > 0) //上百的
{
retVal.append(mE.find(i_3)->second);
retVal.append(" ");
retVal.append(mY.find(1)->second);
i_2 = (tmp % 100) / 10;
if (i_2 > 1)
{
retVal.append(" and ");
retVal.append(mE.find(i_2 * 10)->second);
i_1 = tmp % 10;
if (i_1 > 0)
{
retVal.append(" ");
retVal.append(mE.find(i_1)->second);
}
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
else if (i_2 == 1)
{
retVal.append(" and ");
retVal.append(mE.find(tmp % 100)->second);
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
else
{
i_1 = tmp % 10;
if (i_1 > 0)
{
retVal.append(" and ");
retVal.append(mE.find(i_1)->second);
}
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
}
else
{
i_2 = (tmp % 100) / 10;
if (i_2 > 1)
{
retVal.append(mE.find(i_2 * 10)->second);
i_1 = tmp % 10;
if (i_1 > 0)
{
retVal.append(" ");
retVal.append(mE.find(i_1)->second);
}
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
else if (i_2 = 1)
{
retVal.append(mE.find(tmp % 100)->second);
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
else
{
i_1 = tmp % 10;
if (i_1 > 0)
{
retVal.append(mE.find(i_1)->second);
}
if (flag != 0)
{
retVal.append(" ");
retVal.append(mY.find(flag)->second);
retVal.append(" ");
}
}
}
}
return retVal;
}
std::string BasisTest::parse(long num)
{
std::string retVal;
initMap();
int tmp;
//开始分析 bilion
tmp = num / 1000000000;
if (tmp > 0)
{
retVal.append(mE.find(tmp)->second);
retVal.append(" ");
retVal.append(mY.find(4)->second);
retVal.append(" ");
}
//开始分析 millon
tmp = (num % 1000000000) / 1000000; //235 35 11 3 0
retVal.append(parse_3(tmp,3));
tmp = (num % 1000000) / 1000;
retVal.append(parse_3(tmp,2));
tmp = (num % 1000);
retVal.append(parse_3(tmp,0));
if (retVal.at(retVal.size() -1 ) == ' ')
{
retVal = retVal.substr(0,retVal.size() -1);
}
return retVal;
}
//计票统计
int BasisTest::jipiaotongji(void)
{
int num;
int tnum;
std::string str[128];
std::string tstr[128];
std::map<std::string,int> mapOne;
//输入
std::cin>>num;
if (std::cin.fail())
{
return -1;
}
if (num <= 0)
{
return 0;
}
int i = 0;
while (i < num)
{
std::cin>>str[i];
i++;
}
std::cin>>tnum;
if (std::cin.fail())
{
return -1;
}
if (tnum <= 0)
{
return 0;
}
i = 0;
while (i < tnum)
{
std::cin>>tstr[i];
i++;
}
for (int i = 0; i < num; i++)
{
if (mapOne.find(str[i]) == mapOne.end())
{
mapOne.insert(std::pair<std::string,int>(str[i],0));
}
}
int invalid = 0;
for (int i = 0; i < tnum; i++)
{
if (mapOne.find(tstr[i]) != mapOne.end())
{
mapOne.find(tstr[i])->second ++;
}
else
{
invalid ++;
}
}
//输出
std::map<std::string,int>::iterator the_iterator;
the_iterator = mapOne.begin();
while(the_iterator != mapOne.end())
{
std::cout<<the_iterator->first<<" : ";
std::cout<<the_iterator->second<<std::endl;
the_iterator ++;
}
std::cout<<"Invalid : "<<invalid<<std::endl;
return 0;
}
//ip是否合法
int ipshifouhefa(void)
{
std::string inPara;
std::string strArr[100];
std::cin>>inPara;
if (std::cin.fail())
{
return -1;
}
inPara.append(1,'.');
int j = 0;
int startIndex = 0;
for (unsigned int i = 0; i < inPara.size(); i++)
{
if (inPara.at(i) == '.')
{
strArr[j] = inPara.substr(startIndex,i-startIndex);
j++;
startIndex = i+1;
}
}
bool flag = true;
if (j == 4)
{
for (int i = 0; i < j; i++)
{
if (strArr[i].empty())
{
flag = false;
break;
}
else if (strArr[i].size()>3)
{
flag = false;
break;
}
else
{
for (unsigned int k = 0; k < strArr[i].size(); k++)
{
if (!(strArr[i].at(k) >= '0' && strArr[i].at(k) <= '9'))
{
flag = false;
break;
}
}
int tmp = atoi(strArr[i].c_str());
if (!(tmp >= 0 && tmp < 256))
{
flag = false;
}
}
}
}
else
{
flag = false;
}
if (true == flag )
{
std::cout<<"YES";
}
else
{
std::cout<<"NO";
}
return 0;
}
//百钱买白鸡
int baiqianmaibaiji(void)
{
std::string inPara;
std::cin>>inPara;
std::vector<std::list<int>> vec;
int x,y,z;
for (int i = 25; i >= 0; i--)
{
if ( 0 == ((200 - i * 8) % 14) && 0 == ((1200 - 6 * i) % 14) )
{
x = (200 - 8 * i) / 14;
y = i;
z = (1200 - 6 * i) / 14;
if ((x + y + z) == 100)
{
std::list<int> lis_j;
lis_j.push_back(x);
lis_j.push_back(y);
lis_j.push_back(z);
vec.push_back(lis_j);
}
}
}
for (unsigned int i = 0; i < vec.size(); i++)
{
std::list<int>::iterator theIterator;
int j = 0;
for( theIterator = vec.at(i).begin(); theIterator != vec.at(i).end(); theIterator++ )
{
std::cout << *theIterator;
if (j < 2)
{
std::cout<<" ";
}
j++;
}
std::cout<<std::endl;
}
return 0;
}
//密码强度等级
int mimaqiangdudengji(void)
{
int val = 0;
std::string inPara;
std::cin>>inPara;
if (std::cin.fail())
{
return -1;
}
//字符是否为空
if (inPara.empty())
{
return -1;
}
//密码长度
int len = inPara.size();
if (len <= 4)
{
val +=5;
}
else if (len <=7)
{
val +=10;
}
else
{
val +=25;
}
//判断是否有字母
bool aFlag = false;
bool AFlag = false;
int num_1 = 0;//数字数量
int num_fh = 0;
for (int i = 0; i < len; i++)
{
if (inPara[i] >= 'A' && inPara[i] <='Z' )
{
AFlag = true;
}else if (inPara[i] >='a' && inPara[i] <='z')
{
aFlag = true;
}
else if (inPara[i] >='0' && inPara[i] <='9')
{
num_1 ++;
}
else if ((inPara[i] >= 0x21 && inPara[i] <= 0x2F) || (inPara[i] >= 0x3a && inPara[i] <= 0x40) ||(inPara[i] >= 0x5b && inPara[i] <= 0x60) || (inPara[i] >= 0x7b && inPara[i] <= 0x7e))
{
num_fh ++;
}
}
if (aFlag && AFlag)
{
val +=20;
}
else if (aFlag)
{
val += 10;
}
else if (AFlag)
{
val += 10;
}
else
{
val +=0;
}
//判断数字
if (1 == num_1 )
{
val +=10;
}
else if (num_1 > 1)
{
val +=20;
}
//判断字符
if (1 == num_fh)
{
val += 10;
}
else if (num_fh > 1)
{
val += 25;
}
//奖励
if ((aFlag && AFlag) && num_1 > 0 && num_fh > 0)
{
val += 5;
}
else if ((aFlag || AFlag) && num_1 > 0 && num_fh > 0)
{
val += 3;
}
else if ((aFlag || AFlag) && num_1 > 0)
{
val += 2;
}
//输出
if (val >= 90)
{
std::cout<<"VERY_SECURE";
}
else if (val >= 80)
{
std::cout<<"SECURE";
}
else if (val >= 70)
{
std::cout<<"VERY_STRONG";
}
else if (val >= 60)
{
std::cout<<"STRONG";
}
else if (val >= 50)
{
std::cout<<"AVERAGE";
}
else if (val >= 25)
{
std::cout<<"WEAK";
}
else
{
std::cout<<"VERY_WEAK";
}
return 0;
}
//人民币转换
std::map<int,std::string> BasisTest::mR;
std::map<int,std::string> BasisTest::mD;
void BasisTest::initMap_rmb()
{
//壹、贰、叁、肆、伍、陆、柒、捌、玖
mR.insert(std::pair<int,std::string>(0,"零"));
mR.insert(std::pair<int,std::string>(1,"壹"));
mR.insert(std::pair<int,std::string>(2,"贰"));
mR.insert(std::pair<int,std::string>(3,"叁"));
mR.insert(std::pair<int,std::string>(4,"肆"));
mR.insert(std::pair<int,std::string>(5,"伍"));
mR.insert(std::pair<int,std::string>(6,"陆"));
mR.insert(std::pair<int,std::string>(7,"柒"));
mR.insert(std::pair<int,std::string>(8,"捌"));
mR.insert(std::pair<int,std::string>(9,"玖"));
//拾、佰、仟、万、亿、元、角、分、整
mD.insert(std::pair<int,std::string>(1,"亿"));
mD.insert(std::pair<int,std::string>(2,"万"));
mD.insert(std::pair<int,std::string>(3,"仟"));
mD.insert(std::pair<int,std::string>(4,"佰"));
mD.insert(std::pair<int,std::string>(5,"拾"));
mD.insert(std::pair<int,std::string>(6,"元"));
mD.insert(std::pair<int,std::string>(7,"角"));
mD.insert(std::pair<int,std::string>(8,"分"));
mD.insert(std::pair<int,std::string>(9,"整"));
}
std::string BasisTest::parse(int tmp , int flag)
{
std::string retVal;
int q;//千
int b;//百
int s;//十
int g;//个
if (tmp > 0)
{
q = tmp / 1000;
if (q > 0)
{
retVal.append(mR.find(q)->second);
retVal.append(mD.find(3)->second);
b = (tmp % 1000) / 100;
if (b > 0)
{
retVal.append(mR.find(b)->second);
retVal.append(mD.find(4)->second);
s = (tmp % 100) / 10;
if (s > 0)
{
retVal.append(mR.find(s)->second);
retVal.append(mD.find(5)->second);
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}//end s > 0
else
{
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(0)->second);
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}//end s = 0
}//end b > 0
else
{
s = (tmp % 100) / 10;
if (s > 0)
{
retVal.append(mR.find(0)->second);
retVal.append(mR.find(s)->second);
retVal.append(mD.find(5)->second);
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}//end s > 0
else
{
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(0)->second);
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}//end s = 0
}// end b = 0
}//end q > 0
else
{
b = (tmp % 1000) / 100;
if (b > 0)
{
retVal.append(mR.find(b)->second);
retVal.append(mD.find(4)->second);
s = (tmp % 100) / 10;
if (s > 0)
{
retVal.append(mR.find(s)->second);
retVal.append(mD.find(5)->second);
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}else
{
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(0)->second);
retVal.append(mR.find(g)->second);
}//end g > 0
else
{
}//end g = 0
}//end s = 0
}//end b> 0
else
{
s = (tmp % 100) / 10;
if ( s > 0)
{
retVal.append(mR.find(s)->second);
retVal.append(mD.find(5)->second);
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(g)->second);
}//end g>0
else
{
}//eng g = 0
}
else
{
g = tmp % 10;
if (g > 0)
{
retVal.append(mR.find(g)->second);
}
else
{
}//end g = 0
}//end s = 0
}//end b = 0
}// end q = 0
retVal.append(mD.find(flag)->second);
}
return retVal;
}
int BasisTest::renmibizhuanhuan(void)
{
initMap();
std::string retVal = "人民币";
double inPara;
//输入
std::cin>>inPara;
if (std::cin.fail())
{
return -1;
}
//y
int ytmp = (int)(inPara / 10000.0 / 10000.0);
retVal.append(parse(ytmp,1));
//w
int wtmp = (int)((inPara - ytmp * 100000000.0) / 10000.0);
retVal.append(parse(wtmp,2));
//g
int gtmp = (int)(inPara - ytmp * 100000000.0 - wtmp * 10000.0);
retVal.append(parse(gtmp,6));
//.
int jftmp = (int)((inPara - ytmp * 100000000.0 - wtmp * 10000.0 - gtmp) * 100);
if (jftmp == 0)
{
retVal.append(mD.find(9)->second);
}
else
{
int j = jftmp / 10;
if (j > 0)
{
retVal.append(mR.find(j)->second);
retVal.append(mD.find(7)->second);
int f = jftmp % 10;
if (f > 0)
{
retVal.append(mR.find(f)->second);
retVal.append(mD.find(8)->second);
}//end f > 0
else
{
}//end f = 0
}//end j > 0
else
{
int f = jftmp % 10;
retVal.append(mR.find(0)->second);
retVal.append(mR.find(f)->second);
retVal.append(mD.find(8)->second);
}
}
std::cout<<retVal;
return 0;
}
//计负均正
int jifujunzheng(void)
{
int num;
int arr[1024];
int f_num = 0;
int z_num = 0;
int sum = 0;
std::cin>>num;
if (std::cin.fail())
{
return -1;
}
int i = 0;
while (i < num)
{
std::cin>>arr[i];
if (std::cin.fail())
{
return -1;
}
if (arr[i] > 0)
{
sum += arr[i];
z_num ++;
}
else if (arr[i] < 0)
{
f_num ++;
}
i++;
}
std::cout<<f_num<<" ";
if (sum > 0)
{
if ((sum % z_num) >0)
{
printf("%.1f\n",(((double)sum) / z_num));
}
else
{
std::cout<<sum / z_num;
}
}
else
{
std::cout<<0;
}
return 0;
}
//放苹果
int BasisTest::count(int m, int n)
{
if (m == 0 || n == 1)
{
return 1;
}
if (n > m)
{
return count(m,m);
}
else
{
return count(m, n-1) + count(m-n,n);
}
}
int BasisTest::fangpingguo(void)
{
int m;
int n;
std::cin>>m;
if (std::cin.fail())
{
return -1;
}
std::cin>>n;
if (std::cin.fail())
{
return -1;
}
if (m > 10 || m<0)
{
return -1;
}
if (n<1 || n > 10)
{
return -1;
}
int ret = count(m,n);
std::cout<<ret;
return 0;
}
int BasisTest::tongjiletter(void)
{
std::string inPara;
getline(std::cin,inPara);
int letterNum = 0;//字母
int blankNum = 0;//空格
int digitNum = 0;//数字
int otherNum = 0;//其他
for (unsigned int i = 0; i < inPara.size(); i++)
{
if ((inPara[i] >= 'a' && inPara[i] <= 'z')||(inPara[i] >= 'A' && inPara[i] <= 'Z'))
{
letterNum ++;
}
else if (inPara[i] == ' ' )
{
blankNum ++;
}
else if (inPara[i] <='9' && inPara[i] >='0')
{
digitNum ++;
}
else
{
otherNum ++;
}
}
std::cout<<letterNum<<std::endl;
std::cout<<blankNum<<std::endl;
std::cout<<digitNum<<std::endl;
std::cout<<otherNum<<std::endl;
return 0;
}
//提取不重复的整数
int tiqubuchongfuzhengshu(void)
{
int retVal = 0;
int inPara;
int arr[128];
std::cin>>inPara;
if (std::cin.fail())
{
return -1;
}
int len = 1;//9876673
int index = 0;
bool flag = true;
int tmp = inPara;
int remain = 0;
while (flag)
{
remain = tmp % 10;
{
if (index == 0 && remain == 0)
{
//do nothing
}
else
{
bool haveF = true;
for (int i = 0; i < index; i++)
{
if (arr[i] == remain)
{
haveF = false;
break;
}
}
if (haveF)
{
arr[index] = remain;
index ++;
}
}
}
//
tmp = tmp / 10;
if (tmp == 0)
{
flag = false;
}
}
for (int i = 0; i < index; i++)
{
retVal += arr[i];
if (i != index -1)
{
retVal *= 10;
}
}
std::cout<<retVal;
return 0;
}
//忘记什么东西了
int BasisTest::forgetwhat(void)
{
int num;
std::string strArr[128];
//int intArr[128];
std::map<char,int> mapOne;
std::cin>>num;
if (std::cin.fail())
{
return -1;
}
int i = 0;
while (i < num)
{
std::cin>>strArr[i];
for (unsigned int k = 0; k < strArr[i].size(); k++)
{
if (!((strArr[i][k] >= 'A' && strArr[i][k] <='Z') || (strArr[i][k] >= 'a' && strArr[i][k] <='z')))
{
return -1;
}
}
i++;
}
//循环计算值
for (int i = 0; i < num; i++)
{
std::string tmp = strArr[i];
for (unsigned int j = 0; j < tmp.size(); j++)
{
if (mapOne.find(tmp[j]) == mapOne.end())
{
mapOne.insert(std::pair<char,int>(tmp[j],0));
}
else
{
mapOne.find(tmp[j])->second ++;
}
}
}
return 0;
}
//杨辉三角变形
int BasisTest::yanghuisanjiaobianxing(int x)
{
int ret = -1;
if (x <=2 )
{
}
else
{
int index = x % 4;
if (index == 1 || index == 3)
{
ret = 2;
}
else if (index == 0)
{
ret = 3;
}
else if (index == 2)
{
ret = 4;
}
}
return ret;
}
//求立方根
double BasisTest::getCubeRoot(double input)
{
bool zheng = true;
if (input == 0.0)
{
return 0.0;
}
else if (input < 0)
{
zheng = false;
input *= -1.0;
}
double start = 0.0;
double end = input;
double mid = (end - start) / 2.0;
double xxx = mid * mid * mid;
while (fabs(xxx- input) > 0.001)
{
if (xxx > input)
{
end = mid;
}
else
{
start = mid;
}
mid = (end + start) / 2.0;
xxx = mid * mid * mid;
}
if (!zheng)
{
mid *= -1.0;
}
return mid;
//printf("%.1lf\n", x);输出一位小数
}
//输出单向链表中倒数第k个结点
ListNode* BasisTest::FindKthToTail(ListNode* pListHead, unsigned int k)
{
ListNode *p;
p = pListHead;
int num = 0;
bool flag = true;
while (flag)
{
num++;
if (p->m_pNext == NULL)
{
flag = false;
}
else
{
p = p->m_pNext;
}
}
int s = num - k -1;
p = pListHead;
for (int i = 0; i < s; i++)
{
p = p->m_pNext;
}
return p;
/*
main函数对链表赋值
int num;
std::cin>>num;
if (std::cin.fail())
{
return -1;
}
int i = 1;
ListNode * head;
ListNode * tmpNode;
ListNode * preNode;
tmpNode = new ListNode();
std::cin>>tmpNode->m_nKey;
preNode = tmpNode;
head = tmpNode;
while (i < num)
{
if (i < num-1)
{
tmpNode = new ListNode();
std::cin>>tmpNode->m_nKey;
preNode->m_pNext = tmpNode;
preNode = tmpNode;
}
else
{
tmpNode = new ListNode();
std::cin>>tmpNode->m_nKey;
preNode->m_pNext = tmpNode;
preNode = tmpNode;
preNode->m_pNext = NULL;
}
++i;
}
*/
}
//自守数
int BasisTest::CalcAutomorphicNumbers( int n)
{
/*在这里实现功能*/
int num = 0;
int square = 0;
int remainder = 0;
int index = 1;
for (int i = 0; i <= n; i++)
{
index = 10;
square = i * i;
while (true)
{
remainder = square % index;
if (remainder == i)
{
num++;
break;
}
index *= 10;
if ((index /10) > square)
{
break;
}
}
}
return num;
}

Comment ( 0 )

Sign in for post a comment