一個整數有幾個奇數幾個偶數字
#include<iostream>
#include<cmath>
using namespace std;
int s=0,t=0;
int work(long long x)
{if(x==0)
{t=0;
s=1;}
while(x!=0)
{if((x%10)%2==0)
s++;
else t++;
x/=10;
}
cout<<t<<endl<<s;
}
int main()
{long long n;
cin>>n;
work(abs(n));
return 0;
}
相關推薦
一個整數有幾個奇數幾個偶數字
//一個整數有幾個奇數幾個偶數#include<iostream>#include<cmath>using namespace std;int s=0,t=0;int work(long long x){if(x==0){t=0;s=1;}while(
寫一個函式返回引數二進位制中1的個數+獲取一個數二進位制序列中所有的偶數位和奇數位,分別輸出二進位制序列+輸出一個整數的每一位+兩個int(32位)整數m和n的二進位制表達中,有多少個位(bit)不同
寫一個函式返回引數二進位制中 1 的個數 比如: 15 0000 1111 4 個 1 #include <stdio.h> #include <windows.h> /* 寫一個函式統計一個數二進位制形式下 1 的個數 */ //統計 1 的個數 int C
java--Fibonacc由數字1、1、2、3...組成的,從第三個數字起每一個數字為前兩個數字的和。建立一個方法,接受一個整數引數,顯示從第一個元素開始總共由該引數指定的個數所構成的所有斐波那契數
題目完整描述:一個斐波那契數列是由數字1、1、2、3、5、8、13、21、34等等組成的,其中每一個數字(從第三個數字起)都是前兩個數字的和。建立一個方法,接受一個整數引數,並顯示從第一個元素開始總共由該引數指定的個數所構成的所有斐波那契數字。例如,如果執行 java Fibonacci 5(Fib
每天一道演算法題(二):給定陣列Arr和一個整數aim,請返回哪兩個位置的數可以加出aim來。
給定陣列Arr和一個整數aim,請返回哪兩個位置的數可以加出aim來 例如:arr={2,7,11,15},target = 9 返回{0,1},因為arr[0] + arr[1] = 2 + 7 = 9,可以假設每個數組裡只有一組答案。 大概流程是這樣的: 首先,定義一個
《程式設計師程式碼面試指南》給定一個整數n,返回從1到n的數字中1出現的次數
題目: 給定一個整數n,返回從1到n的數字中1出現的次數。 例如: n=5,1~n為1,2,3,4,5。那麼1出現1次所以返回1。 n=11,1~n為1,2,3,4,5,6,7,8,9,10,11。那麼1出現的次數為1(1,10,11)返回4。 import j
C語言實現判斷一個整數可被3 5 7中哪些數字整除
題目來源:大工慕課 連結 作者:Caleb Sung 注意事項 重點在於if, else if, else的巢狀與混合使用,因而寫法其實並不固定,達成設計目的即可。 解答示範
HBASE列族不能太多的真相 (一個table有幾個列族就有幾個 Store)
gii 大小 mil 更多 觸發 flush adc 同事 就是 今天和同事聊到這個問題,發現者自己理解上有點錯誤。借此機會記錄下 HRegionServer內部管理了一系列HRegion對象,每個HRegion對 應了table中的一個region,HRegion中由多
面試總結:任意一個整數分解為幾個連續正整數之和
前陣子參加了國內某一大公司的面試。到了之後,人家不問出身,不問來歷,就直接開機讓我上機程式設計。因為是第一次在面試時上機操作,儘管題目不是很難,但是由於沒搞清楚機考和筆試的區別,導致最後面試失敗。現在總結一下自己在機考時碰到的一些問題,以免自己以後再犯同樣的錯
已有一個由26字母中的幾個組成的字串(可出現重複),再插入一個字母,能組成多少種字串
小明有26種遊戲海報,用小寫字母a-z表示,小明會把遊戲海報裝訂成冊(可能有重複的海報),冊子可以用一個字串來表示,每個字元就表示對應的海報,例如abcdea,小明現在想做一些“特別版”,然後賣掉,特別版就是會從所有海報(26種)中隨機選一張,加入到冊子的任意一
JavaSE7基礎 得到一個正整數有幾位 String.valueOf(num).length()
ring 代碼 ava 運行 .com value 網上 ima 註意 版本參數:jdk-7u72-windows-i586註意事項:博文內容僅供參考,不可用於其他用途。 代碼 class Demo{ public static void main(String
10.16輸入一個字符串,內有數字和非數字字符,如: a123x456 17960? 302tab5876 將其中連續的數字作為一個整數,依次存放到一數組num中。例如123放在num[0]中,456放在num[1]中……統計共有多少個整數,並輸出這些數。
tab lnp zip sm2 cuc ycm rds qt5 tft 10.16輸入一個字符串,內有數字和非數字字符,如: a123x456 17960? 302tab5876 將其中連續的數字作為一個整數,依次存放到一數組num中。例
Java並發編程有多難?這幾個核心技術你掌握了嗎?
周期 回收 dex 而後 語言 交互 例子 implement 資源 本文主要內容索引 1、Java線程 2、線程模型 3、Java線程池 4、Future(各種Future) 5、Fork/Join框架 6、volatile 7、CAS(原子操作) 8、AQS(並發同步框
劍指offer第32題JS演算法:輸入一個整數n,求從1到n這n個整數的十進位制表示中1出現的次數。例如輸入12,從1到12這些整數中包含1的數字有1,10,11和12,1一共出現了5次
題目:輸入一個整數n,求從1到n這n個整數的十進位制表示中1出現的次數。例如輸入12,從1到12這些整數中包含1的數字有1,10,11和12,1一共出現了5次 這是我某一次去朋友公司面試試水時出的面試題,結果給我五分鐘我寫了個for迴圈的方法,被狠狠鄙視/哭笑不得 結果回來後好奇就跟同事
java獲取一段時間有幾個星期幾
出於專案需求,自己做的筆記 ---------- import java.text.DateFormat; import java.util.Calendar; /** * 給定時間段和星期幾,計算該時間段內共有多少個給定的星期幾 * @param start
如何判斷一個整數位的二進位制中有多少個1
清除整數a最右邊的1可以使用這個操作:a&(a-1) int tatalOne(int number) { int count=0; while(number){ number
有向圖的幾個演算法分析總結
簡介 前面討論的很多文章裡,都是針對無向圖進行的分析。無向圖的一個特性就是其中一旦兩個節點a和b是相連的,這就意味著有路徑從a到b,同時也有從b到a的。它具體對應的矩陣表達方式對應著一個對稱矩陣。而這裡重點是考察有向圖。和無向圖比起來,有向圖更加多了一種出入度的
excel裡的一個單元格怎樣拆分成幾個單元格?
你可以先選中那個單元格---資料--分列, 第一步,選擇“分裂符號”,“下一步”--上面的選一種符號,如果是其它就點“其它”,在後面填上你要的符號,點“下一步”----完成。 這樣就分列到了幾個單元格
[LeetCode-191] Number of 1 Bits(判斷一個整數中有多少個1)
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For
一個整數陣列中,有兩個元素只出現一次,其他所有元素均出現兩次。 找出只出現一次的那兩個元素。(java實現)
一個整數陣列中,有兩個元素只出現一次,其他所有元素均出現兩次。 找出只出現一次的那兩個元素。 思路大概是這樣的:因為除了這兩個只出現一次的數字外,其餘都是成對出現的,有一種運算子,異或運算,兩個相同的數字異或之後為0,所以將陣列中所有的數字依次異或,結果就是這個兩個支出現一
有一個正整數N可以分解成若干個正整數之和,問如何分解能使這些數的乘積最大?
著作權歸作者所有。 商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。 作者:人子立 連結:https://www.zhihu.com/question/30071017/answer/4758474