本题就是给出一个无穷大数,算其是否能被11除尽
Description
Your job is, given a positive numberN, determine if it is a multiple of eleven.
Input specification
The input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.
Output specification
The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
Sample input
112233
30800
2937
323455693
5038297
112234
0
Sample output
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.
使用string模拟除法就可以了。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool divEleven(string s)
{
int carry = 0;
for (int i = 0; i < s.size(); i++)
{
int d = carry * 10 + s[i] - '0';
carry = d % 11;
}
if (carry) return false;
return true;
}
void Eleven()
{
string S;
while (cin>>S && "0" != S)
{
if (divEleven(S)) cout<<S<<" is a multiple of 11.\n";
else cout<<S<<" is not a multiple of 11.\n";
}
}
分享到:
相关推荐
算法课OJ作业-基于HTML的分治和动态规划源码.zip算法课OJ作业-基于HTML的分治和动态规划源码.zip算法课OJ作业-基于HTML的分治和动态规划源码.zip算法课OJ作业-基于HTML的分治和动态规划源码.zip算法课OJ作业-基于...
课程资源 杭电OJ1000-1099答案 ,仅供参考...
OJ系统汇总-2021-10-5(C)-32页.pdf
PAT OJ exercises in C language 纯C语言题解
湖南理工学院OJ的0-100题解.rar
oj_-中国移动BOSS业务规范(推荐PDF186).exe <br>oj_-中国移动BOSS业务规范(推荐PDF186).exe
北邮pythonoj作业-输入行和列树打印田字格
一个下雪的js特效,挺漂亮的,适用于圣诞节,春节等
编译原理OJ-语义分析及目标代码生成c++源码.zip编译原理OJ-语义分析及目标代码生成c++源码.zip编译原理OJ-语义分析及目标代码生成c++源码.zip编译原理OJ-语义分析及目标代码生成c++源码.zip编译原理OJ-语义分析及...
OJ系统汇总-2021-10-5.pdf
实验舱OJ满分题解-1375、冒泡排序过程
OJ系统汇总-2021-10-6(C)-32页.pdf
河南农业大学OJ答案(Java版)
hustoj -- 流行的OJ系统,跨平台、易安装、有题库
全网唯一HP officejet 5200系列打印机初始固件 OJ5200_1904A,用于固件退回,专治升级固件后无法识别墨盒问题
OJ系统汇总-2021-10-5(B).pdf
OJ系统汇总-2021-12-24(d).pdf
山师oj部分题解
sduoj-sandbox.zip
书名:数据结构(C语言版)(第2版) ISBN:9787115379504 作者:严蔚敏 李冬梅 吴伟民