本文主要是介绍UVa 10494 如果我们重返童年,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*
* 解题思路:
* 简单的大整数除法和取模运算
* 有前导0问题,注意即可
*/
#include <stdio.h>
#include <string.h>
#define A 1000
char s[ A ] , c[ 5 ] ;
int n;
int len;
void Divide( )
{int i;int sum[ A ],flag,total;long long tmp1 , tmp2;memset( sum , 0 , sizeof( sum ) );for( i=0;i<len;i++ )sum[ i ] = s[ i ] - '0';tmp1 = tmp2 = 0;for( i=0;i<len;i++ ){tmp1 = 10 * tmp2 + sum[ i ];sum[ i ] = tmp1 / n ;tmp2 = tmp1 % n;}//printf("%d %d\n",sum[ 0 ] , sum[ 1 ]);flag = total = 0;for( i=0;i<len;i++ )if( !flag && sum[ i ]==0 ) total++;else break;for( i=0;i<len-total;i++ )s[ i ] = ( char )(sum[ i +total ] + '0');s[ len-total ] = '\0';if( len - total == 0 )printf("0\n");elseprintf("%s\n",s);
}
void Mod( )
{int i;long long tmp;tmp = 0;for( i=0;i<len;i++ ){tmp = tmp * 10 + s[ i ] -'0';tmp %=n;}printf("%lld\n",tmp);
}
int main( )
{int i;int flag,total;while( ~scanf("%s%s%d",s,c,&n ) ){len = strlen( s );flag = total = 0;for( i=0;i<len;i++ )if( !flag && s[ i ]=='0' ) total++;else break;for( i=0;i<len-total;i++ )s[ i ] = s[ i + total ];s[ len - total ] = '\0';len = len-total;if( c[ 0 ] == '/' )Divide( );elseMod( );}return 0;
}
这篇关于UVa 10494 如果我们重返童年的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!