红尘醉梦kvhvr 题解分享 · 2025/3/18
奇偶统计 - 题解
//循环判断 循环结束条件 cin 为 0 时 while ( cin >> num ) { //(cin >> num) != 0 (error) cin >> 是一个bool值 if ( num == 0 ) { // evenNumber++; 0作为结束符对待 不计入其中 break; } if ( num % 2 == 0 ) { evenNumber++; }else { oddNum += num; } } //输出结果 cout << evenNumber << endl; cout << oddNum << endl; return 0;
查看全文
0 0 0 516
yuri01 题解分享 · 2024/12/12
奇偶统计 - 题解
```cpp #include <bits/stdc++.h> using namespace std; int i; // 输入的数 int num_even = 0; // 偶数计数 int num_odd = 0; // 奇数求和 int main() { while (cin >> i && i) // 判断输入为 0 则结束 if (i % 2 == 0) // 判断奇偶 num_even++; // 偶数 else num_odd += i; // 奇数 cout << num_even << endl << num_odd << endl; // 输出 return 0; } ```
查看全文
0 0 2 474
可爱猫 题解分享 · 2024/8/12
奇偶统计 - 题解
``` #include <iostream> using namespace std; int main() { int a,sum=0,sum2=0; while (true) { cin >> a; if (a == 0) { break; } if (a % 2 == 0) { sum++; } else { sum2+=a; } } cout << sum << endl << sum2; return 0; } 一行+顺便判断,没了 ```
查看全文
0 0 0 505
诗酒趁年华baltm 题解分享 · 2025/3/25
奇偶统计 - 题解
include using namespace std; int main() { int n; int count = 0, con = 0; while (cin >> n) { //可以利用while一直输入 if (n == 0) break; //利用结尾为0,停止输入 if (n % 2 == 0) { count++;//给偶数计数 } if (n % 2 == 1) { con += n;//如果是奇数,那就算所有的奇数之和 } } cout << count << endl << con; return 0; }
查看全文
0 0 0 43
sunday0048 题解分享 · 2025/2/14
奇偶统计 - 题解
public static void main(String[] args) { int n = 0, ou_num = 0, ji_sum = 0; while ((n = sc.nextInt()) != 0) { if (n % 2 == 0) ou_num++; else ji_sum += n; } System.out.println(ou_num); System.out.println(ji_sum); }
查看全文
0 0 0 29
fangxiaorui 题解分享 · 2024/10/24
奇偶统计 - 题解
include include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector arr; int value = 0; int num = 0; int sum = 0; while (1) { cin >> value; if (value != 0) { arr.push_back(value); if (value % 2 == 0) { num++; } else { sum += value; } } else { break; } } ``` cout << "偶数的个数:" << num << endl << "奇数的总值:" << sum << endl; return 0; ``` }
查看全文
0 0 0 34
HZZXhanzhi晗-智 题解分享 · 2024/4/5
奇偶统计 - 题解
``` #include <bits/stdc++.h> using namespace std; int main() { int n, sum1 = 0,sum2 = 0;//sum1为偶数统计,sum2为奇数统计 while(cin >> n && n)//n不等于0便一直读入 { if(n % 2 ==0) sum1++; else sum2 += n; } cout << sum1 <<endl; cout << sum2; return 0; } ```
查看全文
0 0 0 41
zxyllk1314 题解分享 · 2024/4/5
奇偶统计 - 题解
``` //模拟题 #include <iostream> using namespace std; int a,ans,n; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while(cin>>a) { if(a==0)break; if(a%2==0){ n++; } else ans+=a; } cout<<n<<"\n"<<ans; return 0; } `` ```
查看全文
0 0 0 40
yyyrhsss 题解分享 · 2024/4/7
奇偶统计 - 题解
``` #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int o_count = 0; int j_count = 0; while(cin >> n){ if(n == 0) break; else{ if(n % 2 == 0) o_count++; else j_count += n; } } cout << o_count << endl << j_count; return 0; } ```
查看全文
0 0 0 39
Claire 题解分享 · 2024/4/9
奇偶统计 - 题解
n=map(int,input().split()) ans=0 total=0 for i in n: if i==0: break if i%2==0: ans+=1 else: total+=i print(ans) print(total)
0 0 0 38