标签:use amp push pause c++ class long gettime lse
自定义订单号
1 #include<iostream> 2 #include<stack> 3 #include <time.h> 4 #include <sys/timeb.h> 5 #include <string> 6 #include <sstream> 7 8 using namespace std; 9 10 //获取时间戳,精确到毫秒 11 long long getTimeStamp() 12 { 13 timeb t; 14 ftime(&t); 15 return t.time * 1000 ;//+ t.millitm; 16 } 17 18 //将时间戳转换为自定义格式 19 const string m_num = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ"; 20 string tenToX(string& str) 21 { 22 long long n = getTimeStamp(); 23 stack<long long> s; 24 25 while(n) 26 { 27 s.push(n%52); 28 29 n/=52; 30 } 31 while(!s.empty()) 32 { 33 // cout<<m_num[s.top()]; 34 str+=m_num[s.top()]; 35 s.pop(); 36 } 37 return str; 38 } 39 40 //将数字转换为4位字符串 41 string transform(int num) 42 { 43 string res; 44 stringstream ss; 45 ss<<num; 46 ss>>res; 47 if(num<10) 48 { 49 res="000"+res; 50 } 51 else if(num<100) 52 { 53 res ="00"+res; 54 } 55 else if(num<1000) 56 { 57 res="0"+res; 58 } 59 60 return res; 61 } 62 63 //+时间戳转换为自定义格式+4位数自增+4位数随机数 64 int main() 65 { 66 int increment=1001; 67 string str=""; 68 for(int i=0;i<10000;i++) 69 { 70 int randnum=1000+rand()%1000; 71 string tmpstr; 72 tenToX(tmpstr); 73 if(tmpstr==str) 74 { 75 increment++; 76 } 77 else 78 { 79 increment=1001; 80 } 81 str=tmpstr; 82 83 tmpstr = tmpstr + to_string(increment)+to_string((randnum)); 84 cout<<tmpstr<<endl; 85 } 86 system("pause"); 87 return 0; 88 }
标签:use amp push pause c++ class long gettime lse
原文地址:https://www.cnblogs.com/tinghaiku/p/10221976.html