
C/C++
Wang.T
Everything is nothing
展开
-
cin与getline(统计一个字符串里面数字的个数)
cin碰到空格就结束了,所以你就相当于进了三次while循环而getline是读取一行的字符自然你的代码就没问题了原创 2017-11-06 20:30:23 · 1014 阅读 · 0 评论 -
CSUFTACM2017寒假习题解析(第1—3题)
第一题:Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first cipher原创 2018-01-22 18:15:25 · 875 阅读 · 0 评论 -
八种排序方法(一)——选择排序
编译器:Xcode 编程语言:C++ 选择排序的基本思想: 每一趟在n-i+1(i=1,2,3…,n-1)个记录中选取关键字最小的记录与第i个记录交换,并作为有序序列中的第i个记录。例如:待排序列: 43,65,4,23,6,98,2,65,7,79第一趟: 2,65,4,23,6,98,43,65,7,79第二趟: 2,4,65,23,6,98,43,65,7,79第三趟原创 2017-12-14 22:39:48 · 52336 阅读 · 8 评论 -
八种排序方法(二)——冒泡排序
编译器:Xcode 编程语言:C++源程序:#include <iostream>using namespace std;void bubleSort(int a[],int n){ int temp; //运用两个for循环,每次取出一个元素跟数组的其它元素比较,将最大的元素排到最后 for(int i=0;i<n-1;i++) { //外循原创 2017-12-14 22:51:18 · 1339 阅读 · 2 评论 -
关于位运算
1.按位与(&)----对应位全为1则为1,否则为03&5:3:000000115:000001013&5:000000012.按位或(|)----对应为只要有1则为1,否则为03|5:3:000000115:000001013|5:000001113.按位异或(^)----若对应为相同则为0,对应为不同则为13^5:3:000000原创 2017-11-25 10:07:41 · 259 阅读 · 0 评论 -
判断一个数是不是2的整数次幂(两种方法)
方法一:拿这个数来除以2,得到商和余数,再用商除以2,又得到商和余数,重复上面的操作,直到商为0,当商为0,余数也为0时,这个数就是2的整数次幂当商为0,余数不为0时,这个数就不是2的整数次幂。程序如下:#include using namespace std;int fun(int n){ if(n==原创 2017-11-24 22:41:07 · 35519 阅读 · 3 评论 -
C++ STL模版库<queue>
queue的核心接口主要由成员函数push(),front(),back(),pop()构成;push():会将一个元素置入queue中front():会返回queue内的第一个元素(也就是第一个被置入的元素)back():会返回queue中的最后一个元素(也就是最后被插入的元素)pop():会移除queue内的第一个元素(也就是第一个被置入的元素)(1原创 2017-11-08 16:54:22 · 267 阅读 · 0 评论 -
struct和typedef struct
struct和typedef struct分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student s转载 2017-12-08 22:17:15 · 146 阅读 · 0 评论 -
输出从大到小排序的成绩(冒泡排序法)
使用冒泡排序法:#include using namespace std;int main() //输出从大到小排序的成绩{ int n,a[100]; int temp; while(cin>>n) { if(n==0) break;原创 2017-11-06 21:25:18 · 7174 阅读 · 0 评论 -
绝对值排序
输入n(n原创 2017-11-11 14:52:09 · 924 阅读 · 0 评论 -
母牛的故事
母牛的故事:有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?#include using namespace std;int main() //母牛的问题{ int n; long longint a[60]; while(原创 2017-11-11 09:39:59 · 376 阅读 · 0 评论 -
素数的判定二
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39#include using namespace std;int main() { int x,y,n,a; while(cin>>x>>y) { a=0; if(x==0&&y==0)原创 2017-11-09 19:41:49 · 297 阅读 · 0 评论 -
素数的判定
一、#includeusing namespace std;bool f(int m) //素数的判定{ int i; for(i=2;i { if(m%i==0) break; } if(i==m)原创 2017-11-09 19:39:53 · 295 阅读 · 0 评论 -
CSUFTACM2017寒假习题解析(第4—6题)
第四题:Jenny likes balls. He has some balls and he wants to arrange them in a row on the table. Each of those balls can be one of three possible colors: red, yellow, or blue. More precisely, Jenny ha原创 2018-01-23 15:27:47 · 522 阅读 · 0 评论