1217: Problem C
来源:互联网 发布:java webservice加密 编辑:程序博客网 时间:2024/05/22 10:45
题目描述:
题目描述对于给定的字符序列,从左至右将所有的数字字符取出拼接成一个无符号整数(字符序列长度小于100,拼接出的整数小于2^31,),计算并输出该整数的最大因子(如果是素数,则其最大因子为自身) 输入有多组数据,输入数据的第一行为一个正整数,表示字符序列的数目,每组数据为一行字符序列。 输出对每个字符序列,取出所得整数的最大因子,若字符序列中没有数字或者找出的整数为0,则输出0,每个整数占一行输出。 样例输入3sdf0ejg3.f?9f?4afd0s&2d79*(gabcde 样例输出138570
这一题由于题目没叙述清楚,估计后台数据是让求最大质因子,所以这一题郁闷了一天,终于AC了,没有啥算法,其实就是利用了质因子分解的性质,取最大就行了。
AC代码#include <stdio.h>#include <ctype.h>int main(){char s[105];int n;while(~scanf("%d", &n)){int cnt = n;int temp, max;while(cnt --){temp = max = 0;scanf("%s", s);for(int i = 0;s[i];i ++){if(isdigit(s[i]))temp = temp * 10 + s[i] - '0';}if(temp == 0 || temp == 1){printf("%d\n", temp);continue;}for(int i = 2;i * i <= temp;i ++){if(temp % i == 0){max = i;}while(temp % i == 0){temp /= i;}}if(max < temp)max = temp;printf("%d\n",max);}}return 0;}
题目传送门
- 1217: Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem c
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem-C
- Problem C
- Problem C
- Problem C
- Problem-C
- 惊闻Google Reader将被关闭
- python 学习笔记 -- 字符串、数值及运算符
- emacs 安装cedet和ecb
- 双循环链表之分离
- Objective-C中nil与release的区别与用法
- 1217: Problem C
- 编程之美-数组循环移位
- 极点五笔状态栏菜单不显示,如何再让它显示?
- CAD 单位及比例尺
- 3-1调试类
- fireevent在QTP的应用,丰富了控件的行为。
- 黑马程序员 笔记(六)——面向对象(static关键字、静态、main函数、、帮助文档、对象的调用和初始化、单例)
- 第二课堂作业
- 保存在线word编辑的内容到服务器