练习使用向量vector容器。
遍历每个数取余就好了。然后记录下来。
#include<iostream>
#include<vector>
using namespace std;
int main() {
vector<int> B ;
vector<int> C ;
for (int i = 2 ; i <= 60 ; i++) {
vector<int> A ;
int m;
for (int j = 1 ; j < i ; j++) {
m = i % j;
if (m == 0) {
A.push_back(j);
}
}
int sum = 0;
for (unsigned x = 0 ; x < A.size() ; x++ ) {
sum += A[x];
}
if (sum == i) {
B.push_back(i);
} else if (sum > i) {
C.push_back(i);
}
}
cout << 'E' << ':' ;
for (unsigned int i = 0 ; i < B.size() ; i++) {
cout << ' ' << B[i];
}
cout <<'\n' << 'G' << ':' ;
for ( unsigned int i = 0; i < C.size() ; i++) {
cout << ' ' << C[i];
}
return 0;
}
结果如下:
标签:int,盈数,back,C++,vector,push,KY20,sum From: https://www.cnblogs.com/llllmz/p/17970527