题目:Dashboard - Codeforces Round 640 (Div. 4) - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1352
A:整数之和
题解:
#include <bits/stdc++.h>using namespace std;int main() {int t;cin >> t;while (t--) {int n;cin >> n;vector<int> ans;//一个整数的每位存入数组int power = 1;//个位while (n > 0) {if (n % 10 > 0) {ans.push_back((n % 10) * power);}n /= 10;//每存入一次删除一个个位power *= 10;//倍增}cout << ans.size() << endl;for (auto number : ans) cout << number << " ";//输出数组存入的数字cout << endl;}
}
自解:(错误)
#include <iostream>
using namespace std;int main()
{ int k;cin>>k;while(k--){int n;cin>>n;int n1=n;int count=1;while (n1 /= 10){count++; }int a[100] = { 0 };int c=0,s=1;for(int i = count-1; i >=0; i--) {a[i] = n % 10;if(a[i]>0){c++;int s=1;/*for(int j=0;j<count;j++){a[j]=a[i]*s;s*=10;cout<<a[j]<<" ";}*/}n/=10;}cout<<c<<endl;for(int j=0;j<count;j++)cout<<a[j]<<" ";cout<<endl;}return 0;
}
存在问题:
1.数字的倍数及输出
解决:
队友代码:
#include <iostream>
using namespace std;
int main()
{int N;cin >> N;while(N--){int n;cin >> n;int q=n;int i=1,t=0,y=0;while(q!=0){int r;r=q%10;if(r!=0){y++;} q/=10;}cout << y <<endl;while(n>0){int x;x=n%10;i*=10;x*=i;if(x!=0){cout << x/10 << " ";}n/=10;;}cout << endl;}return 0;
}
B:一个数被n个奇数(偶数)求和
题解:
#include <bits/stdc++.h>using namespace std;int main() {int t;cin >> t;while (t--) {int n, k;cin >> n >> k;int n1 = n - (k - 1);if (n1 > 0 && n1 % 2 == 1) {cout << "YES" << endl;for (int i = 0; i < k - 1; ++i) cout << "1 ";cout << n1 << endl;continue;}int n2 = n - 2 * (k - 1);if (n2 > 0 && n2 % 2 == 0) {cout << "YES" << endl;for (int i = 0; i < k - 1; ++i) cout << "2 ";cout << n2 << endl;continue;}cout << "NO" << endl;}
}
C:不能被n整出的第k个数
题解:
#include <bits/stdc++.h>using namespace std;int main() {int t;cin >> t;while (t--) {int n, k;cin >> n >> k;int need = (k - 1) / (n - 1);cout << k + need << endl;}
}