#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
int a[10] = {
0};
for (int i = 0; i < s.length(); i++)
a[s[i] - '0']++;
for (int i = 0; i < 10; i++) {
if (a[i] != 0)
printf("%d:%d\n", i, a[i]);
}
return 0;
}
1022 D进制的A+B
分析:设t = A + B,将每一次t % d的结果保存在int类型的数组s中,然后将t / d,直到 t 等于 0为止,此时s中保存的就是 t 在 D 进制下每一位的结果的倒序,最后倒序输出s数组即可~
#include <iostream>
using namespace std;
int main() {
int a, b, d;
cin >> a >> b >> d;
int t = a + b;
if (t == 0) {
cout << 0;
return 0;
}
int s[100];
int i = 0;
while (t != 0) {
s[i++] = t % d;
t = t / d;
}
for (int j = i - 1; j >= 0; j--)
cout << s[j];
return 0;
}
1023 组个最小数
分析:将数字0、数字1、……数字9的个数分别保存在数组a[i]中,因为0不能做首位,所以首先将i从1到9输出第一个a[i]不为0的数字 i ,并将这个 i 保存在变量 t 中,接着输出a[0]个0,最后输出a[t]-1个 t(因为一个 t 已经被放在首位输出过一次了~) ,最后 i 从 t+1 到 9 输出 a[i] 个 i ~
#include <iostream>
using namespace std;
int main() {
int a[10], t;
for (int i = 0; i < 10; i++)
cin >> a[i];
for (int i = 1; i < 10; i++) {
if (a[i] != 0) {
cout << i;
t = i;
break;
}
}
for (int i = 0; i < a[0]; i++) cout << 0;
for (int i = 0; i < a[t] - 1; i++) cout << t;
for (int i = t + 1; i < 10; i++)
for (int k = 0; k < a[i]; k++)
cout << i;
return 0;
}
1024. 科学计数法
分析:n保存E后面的字符串所对应的数字,t保存E前面的字符串,不包括符号位。当n<0时表示向前移动,那么先输出0. 然后输出abs(n)-1个0,然后继续输出t中的所有数字;当n>0时候表示向后移动,那么先输出第一个字符,然后将t中尽可能输出n个字符,如果t已经输出到最后一个字符(j == t.length())那么就在后面补n-cnt个0,否则就补充一个小数点. 然后继续输出t剩余的没有输出的字符~
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
int i = 0;
while (s[i] != 'E') i++;
string t = s.su

最低0.47元/天 解锁文章

1757

被折叠的 条评论
为什么被折叠?



