随笔分类 -  C++作业题知识点积累

摘要:题目,排队打印问题Input FormatOne line with a positive integer: the number of test cases (at most 20). Then for each test case:One line with two integers n and... 阅读全文
posted @ 2014-05-28 17:34 向日葵的祈愿 阅读(344) 评论(0) 推荐(0)
摘要:比如说我们有一个类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中加牌了 阅读全文
posted @ 2014-03-22 17:15 向日葵的祈愿 阅读(1089) 评论(0) 推荐(0)
摘要: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输出 阅读全文
posted @ 2014-03-16 16:49 向日葵的祈愿 阅读(228) 评论(0) 推荐(0)
摘要: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 + 阅读全文
posted @ 2014-03-09 15:18 向日葵的祈愿 阅读(161) 评论(0) 推荐(0)
摘要:1 //利用to_string函数2 3 int num = 14 5 std::string ss = std::to_string(num); 阅读全文
posted @ 2014-03-09 15:15 向日葵的祈愿 阅读(893) 评论(0) 推荐(0)
摘要:比如说有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 阅读全文
posted @ 2014-03-09 15:03 向日葵的祈愿 阅读(443) 评论(0) 推荐(0)
摘要://使用代码getline(cin,str)std::string ss;std::getline(cin, str) //遇到回车符时结束读取 阅读全文
posted @ 2014-03-09 14:54 向日葵的祈愿 阅读(611) 评论(0) 推荐(0)
摘要:/*如要对齐输出如*1 1,309*2 2.536*3 3.556*12 5.222*///代码如下, left表示左对齐,setw表示长度为10std::cout << std::left << std::setw(10) << num << x << endl; 阅读全文
posted @ 2014-03-09 14:41 向日葵的祈愿 阅读(1861) 评论(0) 推荐(0)
摘要:1 #include double num = 1.6090123;2 3 //输出num精确到小数点后三位4 5 cout << std::fixed << std::setprecision(3) << num << endl; 阅读全文
posted @ 2014-03-09 14:30 向日葵的祈愿 阅读(424) 评论(0) 推荐(0)