现在的位置: 首页 > 综合 > 正文

【2099 整除的尾数】

2014年01月16日 ⁄ 综合 ⁄ 共 992字 ⁄ 字号 评论关闭

整除的尾数

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18689    Accepted Submission(s): 7896

Problem Description
一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢?
 

Input
输入数据有若干组,每组数据包含二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束。
 

Output
对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。
 

Sample Input
200 40 1992 95 0 0
 

Sample Output
00 40 80 15
 

#include<iostream>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b && a!=0 && b!=0){
			int flag=1;
			for(int i=0;i<=99;i++)
			{	
				if((a*100+i)%b==0){
					if(i>=0&&i<=9){
						if(flag){
							cout<<"0"<<i;
							flag=0;
						}
						else
							cout<<" "<<i;
					}
					else {
						if(flag){
							cout<<i;
							flag=0;
						}
						else
							cout<<" "<<i;
					}
				}
					
			}
			cout<<endl;
	}
}

第一种AC代码很乱。

下边思路是:使用数组存储每一个满足条件的数。记住数组要用memset 来初始化。
还有就是最后一个输出数没有空格。可以当一输出。
#include<iostream>

using namespace std;
int main(){
	int a,b;
	int v[100];
	while(cin>>a>>b&&(a||b)){
		int cont=0;
		memset(v,0,sizeof(v));
		for(int i=0;i<=99;i++){
			if((i+a*100)%b==0){
				v[cont++]=i;
			}
		}
		for( i=0;i<cont-1;i++){
			if(v[i]<10)
				cout<<"0";
			cout<<v[i]<<" ";
		}
		if(v[cont-1]<10)
			cout<<"0";
		cout<<v[cont-1]<<endl;
	}
}

使用数组来保存数据,。

抱歉!评论已关闭.