題目連結 UVa 10193
給你兩個二進位字串,找到他們的公倍最大公因數
#include<bits/stdc++.h>
using namespace std;
int dec(string bin)
{
int num=0,arr[bin.length()],i,j;
if(bin[0]=='0')
{
return -1;
}
else
{
for(i=0;i<bin.length();i++)
{
arr[i]=(int)bin[i]-'0';
}
for(i=bin.length()-1,j=0;i>=0;i--,j++)
{
num+=arr[j]*pow(2,i);
}
return num;
}
}
int gcd(int a,int b)
{
if(a==-1 or b==-1)
{
return 0;
}
else
{
while ((a %= b) && (b %= a));
{
return a + b;
}
}
}
int main()
{
int n,c;
string a,b;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a>>b;
cout<<"Pair #"<<i+1;
int c=gcd(dec(a),dec(b));
if(c!=0 and c!=1)
{
cout<<": All you need is love!"<<endl;
}
else
{
cout<<": Love is not all you need!"<<endl;
}
}
}
UVA
回目錄 學習筆記
CPE 一星 UVa 00100 || The 3n + 1 problem UVa 00272 || TEX Quotes UVa 00299 || Train Swapping UVa 00948 || Fibonaccimal Base UVa 10010 || Bangla Numbers UVa 10019 || Funny Encryption Method UVa 10038 || Jolly jumper UVa 10041 || Vito's Family
Oct 1, 2021題目連結 UVa 12019 中文簡述 給你一個日期,算出在2011是星期幾。 [think] 題目有提到說2011/4/4是星期一 可以得知 2011的第93天是星期一
Sep 28, 2021題目連結 UVa 10929 [think] 先換成二進位 再算出二進位有幾個1 solution: #include<iostream> using namespace std; int main() {
Sep 7, 2021DEC BIN 0 0000 1 0001 2
Sep 7, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up