牛客网 二进制数
題目鏈接:https://www.nowcoder.com/practice/103dd589fed14457a673c613d8de3841?tpId=40&tqId=21519&tPage=2&rp=2&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking
題目描述
大家都知道,數(shù)據(jù)在計算機里中存儲是以二進制的形式存儲的。 有一天,小明學了C語言之后,他想知道一個類型為unsigned int 類型的數(shù)字,存儲在計算機中的二進制串是什么樣子的。 你能幫幫小明嗎?并且,小明不想要二進制串中前面的沒有意義的0串,即要去掉前導0。輸入描述:
每行有一個數(shù)字n(0<=n<=10^8),表示要求的二進制串。
輸出描述:
輸出共T行。每行輸出求得的二進制串。示例1
輸入
復制23
輸出
復制10111
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <cstring> 5 #include <stack> 6 using namespace std; 7 int n; 8 int main() 9 { 10 while(cin>>n){ 11 stack<int> s; 12 while(n){ 13 s.push(n%2); 14 n/=2; 15 } 16 while(s.size()>0){ 17 cout<<s.top(); 18 s.pop(); 19 } 20 cout<<endl; 21 } 22 return 0; 23 }
?
轉載于:https://www.cnblogs.com/shixinzei/p/10683555.html
總結
- 上一篇: 检查hpv多少钱啊?
- 下一篇: python语言几个常见函数的使用