#include"bits/stdc++.h"
#include<sstream>
using namespace std;
inline int sum(int i) //inline 关键字
{
return i*i;
}
int main()
{
//rand()
srand(time(NULL));
int x = 5;
printf("%d",rand()%x); //随机输出0 ~ (x - 1)
//sting to int,long long,float,double
string s = "45";
x = stoi(s);
long long ll = stoll(s);
cout<<x<< " " << ll <<endl;
s = "0.001";
double d = stod(s);
cout<<d<<endl;
//stringstream
stringstream ssin;
string S = "123 0.4 abc";
ssin << S;
int a;
float b;
string c;
ssin >>a>>b>>c;
cout<<a<<" "<<b<<" "<<c<<endl;
//getline(istream &is , string &str , char delim)
string data = "1_2_3_4_5_6";
stringstream ss(data);
string item;
cout << data << endl;
while (getline(ss, item, '_'))
cout << item << ' ';
//sscanf(char *str,"%d%d%s", &i,&i2, &s);
string t = "20030121";
int year,month,day;
sscanf(t.c_str(),"%04d%02d%02d",&year,&month,&day);
printf("year = %d, month = %d, day = %d\n",year,month,day);
//sprintf(char *str,""%d%d%s", &i,&i2, &s");
char cc[30];
sprintf(cc,"year = %d, month = %d, day = %d",year,month,day);
puts(cc);
//substr(pos,len);
string g = "1234567890abcd";
t = g.substr(0,4);
cout<<t<<endl;
//strstr(char *str1,char *str2) //kmp算法 O(n)
string j = "0123456789";
string sj = "345";
char *sttt = strstr(j.c_str(),sj.c_str());
printf("c = %c\n",*sttt);
//s.find('a'/"abc") ,O(n^2)
int yy = j.find(sj);
cout<<yy<<endl;
//isdigit()
cout<<isdigit('9')<<endl;
//tolower()
cout<<(char)tolower('A')<<endl;
//toupper()
cout<<(char)toupper('a')<<endl;
//atoi,atoll,atof
char str[] = "123456";
int xx = atoi(str);
cout<<xx<<endl;
return 0;
}