把输入当作一个数,每个1模9后都会余1,所以%9输出即可。当然python更短
#include <iostream> int main() { int a; std::cin >> a; std::cout << a % 9; }