九度1083 1064 1074 1124

九度OJ 1083 特殊乘法 (模拟)

原创  2014年12月16日 12:01:16

题目1083:特殊乘法

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:2910

解决:2027

题目描述:

写个算法,对2个小于1000000000的输入,求结果。

特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

输入:

 两个小于1000000000的数

输出:

 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。

样例输入:
123 45
样例输出:

54

接下来的都比较简单了

#include <iostream>
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main(int argc, char** argv) {
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
int bufa[20],bufb[20],sizea=0,sizeb=0;
while(a!=0)
{
bufa[sizea++]=a%10;
a/=10;
}
while(b!=0)
{
bufb[sizeb++]=b%10;
b/=10;
}
int ans=0;
for(int i=0;i<sizea;i++)
{
for(int j=0;j<sizeb;j++)
{
ans+=bufa[i]*bufb[j];
}
}
printf("%d\n",ans);
}
return 0;
}

题目1064:反序数

题目描述:

设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321)
求N的值

输入:

程序无任何输入数据

输出:

输出题目要求的四位数,如果结果有多组,则每组结果之间以回车隔开

#include <iostream>
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int rev(int n)
{
int tmp=n;
int res=0;
while(tmp>0)
{
res*=10;
res+=tmp%10;
tmp=tmp/10;
}
return res;
}
int main(int argc, char** argv) {
for(int i=1000;i<10000;i++)
{
if(9*i==rev(i))printf("%d\n",i);
}
return 0;
}

题目1074:对称平方数

题目描述:
打印所有不超过n(n<256)的,其平方具有对称性质的数。
如11*11=121
输入:

无任何输入数据

输出:
输出具有题目要求的性质的数。如果输出数据不止一组,各组数据之间以回车隔开。
#include <iostream>
#include<stdio.h>
#include<math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


bool sym(int n)
{
int tmp=n,rev=0;
while(tmp)
{
rev*=10;
rev+=tmp%10;
tmp/=10;
}
if(rev==n)
{
return true;
}
else
{
return false;
}
}
int main(int argc, char** argv) {
for(int i=0;i<256;i++)
{
if(sym(i*i))printf("%d\n",i);

return 0;
}

本来以为很简单的一题居然用了15分钟,要么用字符串,要么刷个小技巧。还好我数学好,把技巧刷出来了。。。

九度oj-1124-Digital Roots

    The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

    For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.

输入:

    The input file will contain a list of positive integers, one per line. 
    The end of the input will be indicated by an integer value of zero.

输出:

    For each integer in the input, output its digital root on a separate line of the output.

样例输入:
24
39
0
样例输出:
6
3
提示:

The integer may consist of a large number of digits.

来源:
2008年北京大学方正实验室计算机研究生机试真题
#include <iostream>
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main(int argc, char** argv) {
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==0)break;
int ans=0;
while(n||(ans>=10))
{
ans+=n%10;
n/=10;
if(n==0&&ans>=10)
{n=ans;
ans=0;}
}
printf("%d\n",ans);
}
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值