Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

甲级第一题不用字符串的写法: #37

Closed
xiaorong61 opened this issue May 7, 2018 · 1 comment
Closed

甲级第一题不用字符串的写法: #37

xiaorong61 opened this issue May 7, 2018 · 1 comment

Comments

@xiaorong61
Copy link
Contributor

#include <stdio.h>
void printFormat(int n) {
  if (n < 0) {                 // 如果 n 负数
    putchar('-');              // 打印负号
    printFormat(-n);           // 用函数自身格式化打印正数
  } else if (n < 1000) {       // 如果 n 介于 [0, 1000)
    printf("%d", n);           // 直接打印
  } else {                     // 如果 n >= 1000
    printFormat(n / 1000);     // 使用函数本身输出去掉低三位的 n
    putchar(',');              // 插入逗号
    printf("%03d", n % 1000);  // 打印低三位
  }
}
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  printFormat(a + b);
  return 0;
}
@liuchuo
Copy link
Owner

liuchuo commented May 8, 2018

啊写的挺好 竟然还有递归~

@liuchuo liuchuo closed this as completed Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants