03 2014 档案
摘要:比如说我们有一个类Card有另外一个类deckOfCard,它里面有一个vector deck现在我们要在deck(类似数组)的后面加牌,有4种花色,一种花色13张牌,那么利用循环 for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { deck.push_back(Card(j, i));}这样就实现了在deck中加牌了
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 int main() { 5 int m, n; 6 cin >> n >> m; 7 int a[m+1][n+1]; 8 memset(a, 0, sizeof(a)); 9 a[1][2] = 1;10 a[1][n] = 1;11 for (int i = 2; i 2->3->1和1->3->2->1,共2种。Input输入共一行,有两个用空格隔开的整数n,m(3<=n<=30,1<=m<=30)。Output输出
阅读全文
摘要:1.写头文件的定义文件时,如Date.h类头文件的定义文件Date.cpp时,成员函数应该加上命名空间 如:int Date::getmonth() {} 不用分号结尾。2.每次写一个类都应该加上 如对于Date.h,要加1 #ifndef DATE_H //大写2 #define DATE_H...
阅读全文
摘要:1 string str(2012-12-05) 2 3 int year, month, day; 4 5 //暴力赋值 6 7 year = (str[0] - '0') * 1000 + (str[1] - '0') * 100; 8 year += (str[2] - '0') * 10 + (str[3] - '0'); 9 month = (str[5] - '0') * 10 + (str[6] - '0');10 day = (str[8] - '0') * 10 +
阅读全文
摘要:1 //利用to_string函数2 3 int num = 14 5 std::string ss = std::to_string(num);
阅读全文
摘要:比如说有string 字符串ss, 找到里面的A字符串,并用B字符串替换 (注意A与B并不一定要等长度) 1 using std::string 2 string ss, A, B; 3 getline(cin, ss); 4 cin >> A; 5 cin >> B; 6 int position = 0; 7 //position用于记录在ss字符串中找到A字符串的位置,npos检测是否到 8 //达ss的末尾 find函数说明在ss的position位置开始寻找A字符串 9 while ((position = ss.find(A, position) != st
阅读全文
摘要://使用代码getline(cin,str)std::string ss;std::getline(cin, str) //遇到回车符时结束读取
阅读全文
摘要:/*如要对齐输出如*1 1,309*2 2.536*3 3.556*12 5.222*///代码如下, left表示左对齐,setw表示长度为10std::cout << std::left << std::setw(10) << num << x << endl;
阅读全文
摘要:1 #include double num = 1.6090123;2 3 //输出num精确到小数点后三位4 5 cout << std::fixed << std::setprecision(3) << num << endl;
阅读全文