题解 | #Digital Roots#

Digital Roots

http://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414

用字符串解决问题 #include #include #include

using namespace std;

int main() { string n; while (getline(cin, n)) { if (n == "ENDOFINPUT") { break; } else { while (n.size() > 1) { int num = 0; for(int i = 0; i < n.size(); i++) { num = num + (n[i] - '0'); } char temp[128]; sprintf(temp, "%d", num); n = temp; } cout << n <<endl; } } return 0; }

全部评论

相关推荐

流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务