Problem Description: Which item
Code Description:
#include <bits/stdc++.h> using namespace std;int main(){int n,m,s=0; cin >> m;for(int i=1;;i++){ s+=i;if(s>m){ cout << i;return 0; } }return 0;}
Output is as follows:
break and continue
Problem Description: Number Recognition
Code is as follows:
#include <bits/stdc++.h> using namespace std;int main(){int n; cin >> n;if(n<10){ cout << 1 << endl; cout << n << endl; }else if(n<100){ cout << 2 << endl; cout << n/10 << endl;//79 7 cout << n%10 << endl;//79 9 }else if(n<1000){ cout << 3 << endl;//789 cout << n/100 << endl; cout << n/10%10 << endl; cout << n%10; }else{ cout << 4 << endl;//9871 cout << n/1000 << endl; cout << n/100%10 << endl; cout << n/10%10 << endl; cout << n%10; }return 0;}
Output is as follows:
Problem Description:Odd and Even Separation
Code is as follows:
#include <bits/stdc++.h> using namespace std;int main(){int n,m,js = 0,os = 0; cin >> n;for(int i=1;i<=n;i++){ cin >> m;if(m%2 == 0){ os++; }else{ js++; } } cout << js << " " << os;return 0;}
Output is as follows:
Homework:7021 Count the 4-digit numbers that meet the conditions