题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
include [HTML_REMOVED]
using namespace std;
const int maxn=31;
char str[maxn],strback[maxn];
int t;
int main()
{
scanf(“%d”,&t);
while(t–){
scanf(“%s”,str);
strcpy(strback,str);
printf(“%s\n”,str);
int len = strlen(str);
for(int i=0;i<len/2;i++) swap(str[i],str[len-i-1]);
while(len>=3){
int x1 = str[0]-'0';
int x2 = str[1]-'0';
if(x2>=x1) str[1]=x2-x1+'0';
else {
str[1]=10+x2-x1+'0';
if(str[2]>'0') str[2]=str[2]-1;
else{
int j=2;
while(j<len && str[j]=='0') str[j++]='9';
str[j]-=1;
}
}
for(int i=1;i<len;i++) str[i-1]=str[i];
len--;
for(int i=len-1 ;i>=0 && str[i]=='0';i--,len--);
for(int i=len-1;i>=0;i--) printf("%c",str[i]);
printf("\n");
}
int res = str[0]-'0'+ 10*(str[1]-'0');
if(res%11==0) printf("The number %s is divisible by 11.\n\n",strback);
else printf("The number %s is not divisible by 11.\n\n",strback);
}
}
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla