1017.A除以B

這裏寫圖片描述

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string a;
  int b;
  cin >> a >> b;
  int temp=0,first = 0;
  for (int i = 0; i < a.length();++i)
  {
    temp = temp * 10 + (a[i] - '0');
    if (temp>=b)
    {
      cout << temp / b;
      first = 1;
    }
    else if (first)
    {
      cout << 0;
    }
    temp = temp%b;
  }
  if (first==0)
  {
    cout << 0;
  }
  cout << ' ' << temp << endl;;
  return 0;
}
發佈了77 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章