Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#include <iostream> using namespace std; int main() { int a = 101; return 0; }
问题:我怎么知道数字 (1) 在变量中重复了两次
如果您查看代码,您将看到该数字101已分配给变量a,并且该数字在十进制表示中具有该数字的1两倍。因此,直接检查是要走的路。我什至不会为这样一个微不足道的要求编写代码。
101
a
1
使用模数 10 和除法 10 来找到它。粗略的想法是,
while( a > 0 ) { if( a % 10 == 1 )count_one++; a=a/10; }