33,311
社区成员
发帖
与我相关
我的任务
分享
#include <map>
#include <iostream>
#include <afx.h>
using namespace std;
int main()
{
CString str=_T("操作员,38d530a786319f0b,2016-2-19 7:12:50|审核员,10b29db7d7b6260a,2016-2-19 7:13:46|管理员,5c775dccb9b89fa5,2016-2-19 7:3:38|操作员,63a99f015106cd44,2016-2-19 6:5:50|操作员,63a99f015106cd44,2016-2-19 8:5:50");
map<CString,CString> mpRecord;
map<CString,CString>::iterator iterRecord;
CString strKey,strData,strTemp;
int pos=0,pos2=0,pos3=0;
while(pos<str.GetLength()) //主循环,一次提取一段到|字符的内容
{
strKey=str.Tokenize(_T(","),pos); //提取**员
strData=str.Tokenize(_T("|"),pos); //提取到|
if((iterRecord=mpRecord.find(strKey))!=mpRecord.end()) //如果在map中有过**员
{
pos2=0;pos3=0;
strData.Tokenize(_T(","),pos2);
(iterRecord->second).Tokenize(_T(","),pos3); //过滤时间之前的内容
const wchar_t split[]=_T("-- ::"); //符号表,分段提取时间,并比较
for(int i=0;i<5;++i)
{
if(_ttoi(strData.Tokenize(&split[i],pos2))>_ttoi((iterRecord->second).Tokenize(&split[i],pos3)))
{
iterRecord->second=strData; //时间新的替换时间旧的
break;
}
}
}
else
{
mpRecord.insert(make_pair(strKey,strData)); //在map中没有出现过,插入新的
}
}
//循环打印map内容
std::locale loc("");
std::wcout.imbue(loc);
for(iterRecord=mpRecord.begin();iterRecord!=mpRecord.end();++iterRecord)
{
wcout<<((iterRecord->first).GetString())<<","<<(iterRecord->second).GetString()<<endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <time.h>
struct tm st;
time_t tt;
char timstr[40];
char tmpbuf[128];
char c;
int t;
int AP() {
if ('P'==c || 'p'==c) {st.tm_hour+=12;return 1;}
if ('A'==c || 'a'==c) return 1;
return 0;
}
int dtparse() {
if (7==sscanf(timstr,"%d/%d/%4d %d:%d:%d %c",&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min,&st.tm_sec,&c)) if (AP()) goto STEP2;
if (6==sscanf(timstr,"%d/%d/%4d %d:%d%c" ,&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min ,&c)) if (AP()) goto STEP1;
if (6==sscanf(timstr,"%4d/%d/%d %d:%d %c" ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min ,&c)) if (AP()) goto STEP1;
if (5==sscanf(timstr,"%d.%d.%4d %d:%d" ,&st.tm_mon ,&st.tm_mday,&st.tm_year,&st.tm_hour,&st.tm_min )) goto STEP1;
if (6==sscanf(timstr,"%4d-%d-%d %d:%d:%d" ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min,&st.tm_sec )) goto STEP2;
STEP1:
st.tm_sec=0;
STEP2:
st.tm_year-=1900;
if (st.tm_mon>12) {t=st.tm_mon;st.tm_mon=st.tm_mday;st.tm_mday=t;}
st.tm_mon-=1;
tt=mktime(&st);
if (-1!=tt) {
strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&tt));
return 1;
} else {
printf("[%s] is Invalid time string!\n",timstr);
return 0;
}
}
int main() {
strcpy(timstr,"10.01.2012 15:43" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"8/11/2006 11:10AM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"2006/10/31 04:50 PM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"1/6/2010 5:20:12 PM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"13/12/2012 11:16:17 a.m.");if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"2013-06-08 09:56:59" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
return 0;
}
//[10.01.2012 15:43] is [2012-10-01 15:43:00]
//[8/11/2006 11:10AM] is [2006-11-08 11:10:00]
//[2006/10/31 04:50 PM] is [2006-10-31 16:50:00]
//[1/6/2010 5:20:12 PM] is [2010-06-01 17:20:12]
//[13/12/2012 11:16:17 a.m.] is [2012-12-13 11:16:17]
//[2013-06-08 09:56:59] is [2013-06-08 09:56:59]
//
difftime
Finds the difference between two times.
double difftime( time_t timer1, time_t timer0 );
Routine Required Header Compatibility
difftime <time.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double-precision floating-point number.
Parameters
timer1
Ending time
timer0
Beginning time
Remarks
The difftime function computes the difference between the two supplied time values timer0 and timer1.
Example
/* DIFFTIME.C: This program calculates the amount of time
* needed to do a floating-point multiply 10 million times.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main( void )
{
time_t start, finish;
long loop;
double result, elapsed_time;
printf( "Multiplying 2 floating point numbers 10 million times...\n" );
time( &start );
for( loop = 0; loop < 10000000; loop++ )
result = 3.63 * 5.27;
time( &finish );
elapsed_time = difftime( finish, start );
printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
}
Output
Multiplying 2 floats 10 million times...
Program takes 2 seconds.
Floating-Point Support Routines | Time Management Routines
See Also time
#include <stdio.h>
#include <string.h>
char string[80];
char seps1[3];
char seps2[3];
char *token;
char *zzstrtok (
char *string,
const char *control1,//连续出现时视为中间夹空token
const char *control2 //连续出现时视为中间无空token
)
{
unsigned char *str;
const unsigned char *ctrl1 = control1;
const unsigned char *ctrl2 = control2;
unsigned char map1[32],map2[32];
static char *nextoken;
static char flag=0;
unsigned char c;
int L;
memset(map1,0,32);
memset(map2,0,32);
do {
map1[*ctrl1 >> 3] |= (1 << (*ctrl1 & 7));
} while (*ctrl1++);
do {
map2[*ctrl2 >> 3] |= (1 << (*ctrl2 & 7));
} while (*ctrl2++);
if (string) {
if (control2[0]) {
L=strlen(string);
while (1) {
c=string[L-1];
if (map2[c >> 3] & (1 << (c & 7))) {
L--;
string[L]=0;
} else break;
}
}
if (control1[0]) {
L=strlen(string);
c=string[L-1];
if (map1[c >> 3] & (1 << (c & 7))) {
string[L]=control1[0];
string[L+1]=0;
}
}
str=string;
}
else str=nextoken;
string=str;
while (1) {
if (0==flag) {
if (!*str) break;
if (map1[*str >> 3] & (1 << (*str & 7))) {
*str=0;
str++;
break;
} else if (map2[*str >> 3] & (1 << (*str & 7))) {
string++;
str++;
} else {
flag=1;
str++;
}
} else if (1==flag) {
if (!*str) break;
if (map1[*str >> 3] & (1 << (*str & 7))) {
*str=0;
str++;
flag=0;
break;
} else if (map2[*str >> 3] & (1 << (*str & 7))) {
*str=0;
str++;
flag=2;
break;
} else str++;
} else {//2==flag
if (!*str) return NULL;
if (map1[*str >> 3] & (1 << (*str & 7))) {
str++;
string=str;
flag=0;
} else if (map2[*str >> 3] & (1 << (*str & 7))) {
str++;
string=str;
} else {
string=str;
str++;
flag=1;
}
}
}
nextoken=str;
if (string==str) return NULL;
else return string;
}
void main()
{
strcpy(string,"A \tstring\t\tof ,,tokens\n\nand some more tokens, ");
strcpy(seps1,",\n");strcpy(seps2," \t");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"1234| LIYI|China | 010 |201110260000|OK");
strcpy(seps1,"|");strcpy(seps2," ");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"1234|LIYI||010|201110260000|OK");
strcpy(seps1,"");strcpy(seps2,"|");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"1234|LIYI||010|201110260000|OK");
strcpy(seps1,"|");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"a");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"a,b");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"a,,b");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",a");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,"a,");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",a,,b");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",,a,,b,,");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",,");
strcpy(seps1,",");strcpy(seps2,"");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
strcpy(string,",,,");
strcpy(seps1,",");strcpy(seps2," ");
printf("\n[%s]\nTokens:\n",string);
token=zzstrtok(string,seps1,seps2);
while (token!=NULL) {
printf(" <%s>",token);
token=zzstrtok(NULL,seps1,seps2);
}
}
//
//[A string of ,,tokens
//
//and some more tokens,]
//Tokens:
// <A>, <string>, <of>, <>, <tokens>, <>, <and>, <some>, <more>, <tokens>, <>,
//[1234| LIYI|China | 010 |201110260000|OK]
//Tokens:
// <1234>, <LIYI>, <China>, <010>, <201110260000>, <OK>,
//[1234|LIYI||010|201110260000|OK]
//Tokens:
// <1234>, <LIYI>, <010>, <201110260000>, <OK>,
//[1234|LIYI||010|201110260000|OK]
//Tokens:
// <1234>, <LIYI>, <>, <010>, <201110260000>, <OK>,
//[a]
//Tokens:
// <a>,
//[a,b]
//Tokens:
// <a>, <b>,
//[a,,b]
//Tokens:
// <a>, <>, <b>,
//[,a]
//Tokens:
// <>, <a>,
//[a,]
//Tokens:
// <a>, <>,
//[,a,,b]
//Tokens:
// <>, <a>, <>, <b>,
//[,,a,,b,,]
//Tokens:
// <>, <>, <a>, <>, <b>, <>, <>,
//[,]
//Tokens:
// <>, <>,
//[,,]
//Tokens:
// <>, <>, <>,
//[,,,]
//Tokens:
// <>, <>, <>, <>,
#include <stdio.h>
#include <string.h>
#include <locale.h>
char s[256];
char *p;
int r,n,i;
int main() {
setlocale(LC_ALL,"chs");
while (1) {
printf("请输入一行文字(空行结束),\"%%20\"将替换为\" \",\"你懂得\"将替换为\"XXXXXX\":\n");
fgets(s,256,stdin);
if ('\n'==s[0]) break;
p=s;
while (1) {
p=strstr(p,"%20");
if (p) {
memmove(p+1,p+3,strlen(p)-3+1);
p[0]=' ';
} else break;
}
p=s;
while (1) {
p=strstr(p,"你懂得");
if (p) {
memmove(p+6,p+6,strlen(p)-6+1);
for (i=0;i<6;i++) p[i]='X';
} else break;
}
printf("%s",s);
}
return 0;
}
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//abcdefg%20helloworld%20something.pdf
//abcdefg helloworld something.pdf
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//这是测试文字你懂得,在这个你懂的地方,就得做你懂得的事
//这是测试文字XXXXX,在这个你懂的地方,就得做XXXXX的事
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//