栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1047 Round and Round We Go

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1047 Round and Round We Go

#include<stdio.h>#include<string.h> char *strrev( char *s ){if( s == NULL || s[ 0 ] == '' )return s;for( char t, *p = s, *q = s + strlen( s ) - 1; p < q; p++, q-- )t = *p, *p = *q, *q = t;return s;}int main(){char input[ 65 ];char c1[ 65 ], c2[ 130 ];int length;int i, j, k, p, q;int flag;while( memset( input, 0, sizeof( input ) ) && scanf( "%s", input ) != EOF ){length = strlen( input );memset( c1, 0, sizeof( c1 ) );strncpy( c1, input, length );//复制到c1 strrev( c1 ); //倒置 // 用来判断循环数,例如 142857 ,c2 就为 142857142857,结果只要是 c2 的子串,就是循环的memset( c2, 0, sizeof( c2 ) );strncpy( c2, c1, length ); strncpy( c2 + length, c1, length );flag = 1;for( i = 2; i <= length; i++ ){for( j = 0; j < length; j++ ){c1[ j ] += ( c2[ j ] - '0' );if( c1[ j ] > '9' ){c1[ j ] -= 10;++ c1[ j + 1 ];}}if( strlen( c1 ) > length ){flag = 0;break;}if( !strstr( c2, c1 ) ){flag = 0;break;}}if( flag )printf( "%s is cyclicn", input );elseprintf( "%s is not cyclicn", input );}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373290.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号