A.Helpful Maths

分析:将读入的字符转化为数字,直接排个序就可以了。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 500;
int seq[N];

int main() {
    char c;
    int t = 0, idx = 0;
    while ((c = getchar()) != EOF) {
        if (c == '+' || c == '\n') {
            seq[idx++] = t;
            t = 0;
        }
        else t = t * 10 + c - '0';
    }
    sort(seq, seq+idx);
    printf("%d", seq[0]);
    for (int i = 1;  i < idx; ++i) printf("+%d", seq[i]);
    puts("");
    return 0;
} 
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-08-12
  • 2021-04-24
  • 2021-12-04
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案