- 博客(119)
- 收藏
- 关注
原创 八皇后(还有待改进)
呃,实习开始了。由于当初选错方向的问题,无奈实习只能跟着中软(中软国际)学做网站项目。不太喜欢JAVA,但并不是说JAVA不好,前几天看的一个位操作,那个用JAVA的人写的代码也挺精湛的。不扯废话,上午没事,就想着写了个N皇后问题的代码。上午卡在了斜线的处理上,卡了两个小时。。。汗~!结果回去睡了个午觉,再调的时候没几分钟就弄好了。。。我个人感觉代码还有待改进,先把思路记录下。整体思路
2014-01-11 13:46:42
805
转载 Sample 6.1:if.cpp
#includeint main(){ using namespace std; char ch; int spaces = 0; int total = 0; cin.get(ch); while(ch != '.') { if(ch == ' ') ++spaces; ++tot
2013-12-28 08:09:14
609
原创 Exercise 5.9
#includeusing namespace std;int main(){ cout << "Enter number of rows:"; int n; cin >> n; for(int i = 0;i < n;i++) { for(int k = 0;k < n - i - 1;k++) cout
2013-12-28 08:02:30
582
原创 Exercise 5.8
#include#includeusing namespace std;int main(){ string word; int number = 0; cout << "Enter words (to stop, type the word done):" << endl; while(cin >> word && word != "done")
2013-12-28 07:57:20
516
原创 人人code,整数取反
题目很简单,完成函数reverse,要求实现把给定的一个整数取其相反数的功能,举两个例子如下: x = 123, return 321 x = -123, return -321#include#include#includeusing namespace std;vector c;void reverse(int);int main(){ int n; c
2013-12-28 07:43:48
532
原创 Exercise 5.7
#include#include#define ArSize 50using namespace std;int main(){ char word[ArSize]; int number = 0; int x; cout << "Enter words (to stop, type the word done):" << endl; whil
2013-12-28 07:16:13
529
原创 Exercise 5.6
#include#define ArSize 50using namespace std;struct car{ char productor[ArSize]; int year;};int main(){ int n; cout << "How many cars you wish to catalog?"; cin >> n; c
2013-12-25 20:06:56
531
原创 Exercise 5.5
#include#includeusing namespace std;int main(){ string Months[12] = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
2013-12-25 19:41:56
453
转载 Sample 5.20:nested.cpp
#includeconst int Cities = 5;const int Years = 4;int main(){ using namespace std; const char * cities[Cities] = { "Gribble City", "Gribbletown",
2013-12-25 19:30:17
582
转载 Sample 5.19:textin4.cpp
#includeint main(){ using namespace std; int ch; int count = 0; while((ch = cin.get()) != EOF){ cout.put(char(ch)); ++count; } cout << endl << count << " char
2013-12-25 19:29:31
613
转载 Sample 5.18:textin3.cpp
#includeint main(){ using namespace std; char ch; int count = 0; cin.get(ch); while(cin.fail() == false){ cout << ch; ++count; cin.get(ch); } cout
2013-12-25 19:29:01
517
转载 Sample 5.17:textin2.cpp
#includeint main(){ using namespace std; char ch; int count = 0; cout << "Enter characters; enter # to quit:\n"; cin.get(ch); while(ch != '#') { cout << ch;
2013-12-25 19:28:25
562
转载 Sample 5.16:textin1.cpp
#includeint main(){ using namespace std; char ch; itn count = 0; cout << "Enter characters; enter # to quit:\n"; cin >> ch; while(char != '#'){ cout << ch; ++
2013-12-25 19:27:59
697
转载 Sample 5.15:dowhile.cpp
#includeint main(){ using namespace std; int n; cout << "Enter numbers in the range 1-10 to find "; cout << "my favorite number\n"; do{ cin >> n; }while(n != 7);
2013-12-25 19:27:25
460
转载 Sample 5.14:waiting
#include#includeint main(){ using namespace std; cout << "Enter the dealy time ,in seconds: "; float secs; cin >> secs; clock_t delay = secs * CLOCKS_PER_SEC; cout << "start
2013-12-25 19:26:55
503
转载 Sample 5.13:while.cpp
#includeconst int ArSize = 20;int main(){ using namespace std; char name[ArSize]; cout << "Your first name,please:"; cin >> name; cout << "Here is your name, verticalize
2013-12-25 19:26:26
502
转载 Sample 5.12:comstr2.cpp
#include#includeint main(){ using namespace std; string word = "?ate"; for(char ch = 'a';word != "mate";char++){ cout << word << endl; word[0] = ch; } cout << "
2013-12-25 19:25:43
548
转载 Sample 5.11:comstr1.cpp
#include#includeint main(){ using namespace std; char word[5] = "?ate"; for(char ch = 'a';strcmp(word,"mate");ch++){ cout << word << endl; word[0] = ch; } cout
2013-12-25 19:25:03
624
原创 今天晚上。。。
今天本来痛下决心,痛定思痛,一定晚上要看英语,要考六级了。。。结果。。。结果快递的小哥给我来个电话,我东西到了。。。我都郁闷,我似乎没有买什么啊~等我打开包裹一看,哈哈哈,新买的单片机到了,,结果。。。今晚的结果我已经看到了。。。明天好好复习英语吧,今晚赶紧拿着单片机新鲜新鲜,嘿嘿算是给单片机学习开个序吧
2013-12-09 18:41:05
547
原创 二进制数转十进制数
C++代码实现:#include#include#include#includeusing namespace std;int main(){ ifstream in("abc.txt"); for (string a ;in>>a&&a!="-1";) { double x=0; int t=a.length();
2013-12-08 21:54:03
612
原创 十进制数转二进制数
C++代码实现:#include#include#include#include#includeusing namespace std;int main(){ ifstream in("abc.txt"); for (string a ;in>>a&&a!="-1";) { vector last; int x=0;
2013-12-08 21:53:14
662
原创 2.3-4
C++代码实现:MERGE(A,p,q,r) n1 <- q-p+1 n2 <- r-q; create arrays L[1...n1] and R[1...n2] for i <- 1 to n1 do L[i] <- A[p+i-1] for j <- 1 to n2 do R[j] <- A[q+j] m1
2013-12-08 21:52:04
473
原创 2.3-2
分治排序无哨兵位伪代码:MERGE(A,p,q,r) n1 <- q-p+1 n2 <- r-q; create arrays L[1...n1] and R[1...n2] for i <- 1 to n1 do L[i] <- A[p+i-1] for j <- 1 to n2 do R[j] <- A[q+j]
2013-12-08 21:47:34
498
转载 Sample 5.10: equal.cpp
#includeint main(){ using namespace std; int quizscores[10] = { 20,20,20,20,20,19,20,18,20,20 }; cout << "Doing it right: \n"; int i ; for(i = 0;quizs
2013-12-08 21:35:33
462
转载 Sample 5.9: forstr2.cpp
#include#includeint main(){ using namespace std; cout << "Enter a word: "; string word; cin >> word; char temp; int i,j; for(j = 0,i = word.size() - 1;j < i;--1,++j){
2013-12-08 21:34:43
451
转载 Sample 5.8: block.cpp
#includeint main(){ using namespace std; cout << "The Amazing Accounto wii lsum and average "; cout << "five number s for you.\n"; cout << "Please enter five values:\n"; double n
2013-12-08 21:34:14
453
转载 Sample 5.7:plus_one.cpp
#includeint main(){ using namespace std; int a = 20; int b = 20; cout << "a = " << a << "; b = " << b << "\n"; cout << "a++ = " << a++ << "; ++b = " << ++b << "\n"; cout << "
2013-12-08 21:33:22
478
转载 Sample 5.6: fprstr1.cpp
#include#includeint main(){ using namespace std; cout << "Enter a word: "; string word; cin >> word; for(int i = word.size() - 1;i >= 0;i--) cout << word[i]; cout <<
2013-12-08 21:32:52
468
转载 Sample 5.5: bigstep.cpp
#includeint main(){ using namespace std; cout << "Enter an integer: "; int by; cin >> by; cout << "Counting by " << by << "s: \n"; for(int i = 0;i < 100;i++) cout <<
2013-12-08 21:31:38
376
转载 Sample 5.4: formore.cpp
#includeusing namespace std;const int ArSize = 16;int main(){ double factorials[ArSize]; factorials[1] = factorials[0] = 1.0; int i; for(i = 2;i < ArSize;i++) factorials[i]
2013-12-08 21:31:04
470
转载 Sample 5.3:express.cpp
#includeusing namespace std;int main(){ int x; cout << "The expression x = 100 has the value "; cout << (x = 100) << endl; cout << "Now x = " << x << endl; cout << "The expressi
2013-12-08 21:30:29
396
转载 Sample 5.2:num_test.cpp
#includeint main(){ using namespace std; cout << "Enter the starting countdown value:"; int limit; cin >> limit; int i; for(i = limit;i;i--) cout << "i = " << i << "\
2013-12-08 21:29:48
507
转载 Sample 5.1:forloop.cpp
#includeint main(){ using namespace std; int i; for( i = 0;i < 5;i++) cout << "C++ knows loops.\n"; cout << "C++ know when to stop.\n"; return 0;}
2013-12-08 21:29:06
502
原创 Exercise 5.4
#include#includeint main(){ using namespace std; string Months[12] = { "January", "February", "March", "April", "May", "June", "J
2013-12-08 21:27:28
466
原创 Exercise 5.3
#includeint main(){ using namespace std; double Daphne_rate = 0.1; double Cleo_rate = 0.05; double Daphne = 100; double Cleo = 100; int i = 0; while(Cleo <= Daphne) {
2013-12-08 21:20:52
557
原创 Exercise 5.2
#includeint main(){ using namespace std; int m; int n = 0; cout << "请输入一个整数(0结束):"; while(cin >> m && m != 0){ n += m; cout << "目前为止,所有输入整数的和为:" << n << endl;
2013-12-08 21:08:30
411
原创 Exercise 5.1
#includeint main(){ using namespace std; int m,n; cout << "请输入较小的整数:"; cin >> m; cout << "请输入较大的整数:"; cin >> n; int sum = 0; for(;m <= n;m++){ sum += m; }
2013-12-08 21:04:31
457
原创 分治排序(有哨兵位)
C++代码:#includevoid MERG(int *A,int p,int q,int r){ int n = p - q + 1; int m = r - q; int L = new int [n+1]; int R = new int [m+1]; int i, j; for(i = 0;i < n - 1;i++)
2013-12-05 21:09:54
561
原创 2.2-3 & 2.2-4
2.2-3n/2个;n个;O(n)解答:平均查找一般就能查出结果,前提是序列中有要查询的元素。最坏情况就是没有该元素出现在待查队列中,要进行全部扫描,所以查n次,O(n)为时间复杂度。2.2-4首先分析问题的要求,找出要解决问题的一个思路。然后寻找多个有效的解决问题方法,中啊出相对最好的方法,然后改进算法,在一定范围内缩小数据规模。
2013-12-05 21:01:00
494
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人