AcWing 708. 偶数
#include <iostream>
using namespace std;
int main()
{
for(int i = 1; i <= 100; i++)
{
if((i&1) == 0) //位运算 。偶数和1 &位元算为0
{
cout<<i<<endl;
}
}
return 0;
}
AcWing 709. 奇数
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
if((i&1) != 0) //位运算 。偶数和1 &位元算为0
{
cout<<i<<endl;
}
}
return 0;
}
AcWing 712. 正数
#include <bits/stdc++.h>
using namespace std;
int main(){
int x = 0;
for(int i = 1;i <= 6;i++){
double t;
cin >> t;
if(t > 0) x++;
}
cout << x << " positive numbers";
return 0;
}
AcWing 714. 连续奇数的和 1
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int x,y;
int ans=0;
cin>>x>>y;
if(x>y) swap(x,y);
for(int i=x+1;i<y;i++){
if(i%2) ans+=i;
}
printf("%d\n",ans);
return 0;
}
AcWing 716. 最大数和它的位置
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[111];
int b[111];
const int N = 100;
int main()
{
for (int i = 0; i < N; i ++ ){
cin >> a[i];
b[i] = a[i];
}
sort(a,a+N);
for (int i = 0; i < N; i ++ ){
if(b[i] == a[N-1])
printf("%d\n%d",a[N-1],i+1);
}
return 0;
}
AcWing 721. 递增序列
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n;
while(cin >> n && n!=0){
for(int i = 1; i <= n; i++){
printf("%d ",i);
}
printf("\n");
}
return 0;
}
AcWing 720. 连续整数相加
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, n, t = 0;
cin >> a;
while(cin >> n){
if(n > 0){
for(int i = 1;i <= n;i++){
t += a;
a ++;
}
}
}
cout << t;
return 0;
}
AcWing 724. 约数
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int i,a[1000];
int main()
{
int n;
cin >> n;
for (i = 1; i <= n; i ++ ){
if(n % i == 0) printf("%d\n",i);
}
return 0;
}
AcWing 723. PUM
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c = 1;
cin >> a >> b;
for(int i = 0; i < a; i++){
for(int j = 0; j < b - 1; j++){
printf("%d ",c); c++;
}
c++;
printf("PUM\n");
}
return 0;
}