跳到正文

题解

UVA11701 Cantor 题解

陈思行约 1 分钟
原文
文章信息与版本

文章信息

发布
2021年4月2日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 1 分钟
获赞
1
题目
UVA11701

版本

  1. v1当前

判断0-1之间的十进制小数转换成三进制小数后有没有含1,含有输出NON-MEMBER,不含有输出MEMBER

C++
#include <bits/stdc++.h>
using namespace std;
string s;
string Itoa(double Num) {
	string remain="";
	int k=100;
	int temp;
	do {
		Num*=3;
		temp=int(Num);
		Num-=temp;
		remain += temp + '0';
	} while (--k);
	reverse(remain.begin(),remain.end());
	return remain;
}
int main() {
	double a;
	int b,m=0;
	while(scanf("%lf",&a)==1) {
		s=Itoa(a);
		for(int i=0; i<=s.size(); i++) {
			if(s[i]=='1'){
				cout<<"NON-MEMBER"<<endl;
				m=1;
				break;
			}
		}
		if(!m){
			cout<<"MEMBER"<<endl;
		}
	}
}
原文