对于任意两个正整数x和k,我们定义repeat(x, k)为将x重复写k次形成的数,例如repeat(1234, 3) = 123412341234,repeat(20,2) = 2020.
牛牛现在给出4个整数x1, k1, x2, k2, 其中v1 = (x1, k1), v2 = (x2, k2),请你来比较v1和v2的大小。
输入包括一行,一行中有4个正整数x1, k1, x2, k2(1 ≤ x1,x2 ≤ 10^9, 1 ≤ k1,k2 ≤ 50),以空格分割
如果v1小于v2输出"Less",v1等于v2输出"Equal",v1大于v2输出"Greater".
1010 3 101010 2
Equal
#include<iostream> #include<string> using namespace std; int main(){ string str1,str2,out1,out2; int k1,k2; cin>>str1>>k1>>str2>>k2; if(str1.size()*k1<str2.size()*k2) cout<<"Less"<<endl; else if(str1.size()*k1>str2.size()*k2) cout<<"Greater"<<endl; else{ for(int i=0;i<k1;i++) out1+=str1; for(int i=0;i<k2;i++) out2+=str2; if(out1==out2) cout<<"Equal"<<endl; else if(out1<out2) cout<<"Less"<<endl; else cout<<"Greater"<<endl; } }
// 输入均为整数: #include<iostream> #include<vector> using namespace std; int countBits(int x){ int bit = 1; while(x/10>0){ bit++; x /= 10; } return bit; } int changeNum(int bit1, int bit2, int num){ vector<int> v(bit2); for(int i=bit2-1; i>=0; i--){ v[i] = num%10; num /= 10; } for(int i=0; i<bit1; i++){ num = num*10 +v[i%bit2]; } return num; } int main(){ int x1,k1,x2,k2; cin >> x1 >> k1 >> x2 >> k2; int bit1 = countBits(x1); int bit2 = countBits(x2); if(bit1*k1 > bit2*k2){ cout << "Greater" << endl; } else if(bit1*k1 < bit2*k2){ cout << "Less" << endl; } else{ if(bit1 > bit2){ x2 = changeNum(bit1, bit2, x2); } else if(bit1 < bit2){ x1 = changeNum(bit2, bit1, x1); } if(x1 > x2) cout << "Greater" << endl; else if(x1 < x2) cout << "Less" << endl; else cout << "Equal" << endl; } return 0; } //输入字符串的版本: #include<iostream> #include<string> using namespace std; int main(){ string x1,x2; int k1,k2; cin >> x1 >> k1 >> x2 >> k2; int len1 = x1.length(); int len2 = x2.length(); if(len1*k1 > len2*k2){ cout << "Greater" << endl; } else if(len1*k1 < len2*k2){ cout << "Less" << endl; } else{ if(len1 < len2){ for(int i=len1; i<len2; i++){ x1 += x1[i%len1]; } } else if(len1 > len2){ for(int i=len2; i<len1; i++){ x2 += x2[i%len2]; } } if(x1 > x2) cout << "Greater" << endl; else if(x1 < x2) cout << "Less" << endl; else cout << "Equal" << endl; } return 0; }
import java.util.*; import java.math.*; public class Main { public static void main(String []args){ Scanner in=new Scanner(System.in); String s1=in.next(),s2,a="",b=""; int k1=in.nextInt(),k2,i; s2=in.next();k2=in.nextInt(); for(i=0;i<k1;i++) a+=s1; for(i=0;i<k2;i++) b+=s2; BigInteger x=new BigInteger(a),y=new BigInteger(b); System.out.printf("%s",x.compareTo(y)>0?"Greater":x.compareTo(y)<0?"Less":"Equal"); } }
def repeat(x,k): return int(x*k) x1,k1,x2,k2=list(input().split()) if repeat(x1,int(k1))<repeat(x2,int(k2)): print("Less") elif repeat(x1,int(k1))==repeat(x2,int(k2)): print("Equal") else: print("Greater")
#include <bits/stdc++.h> using namespace std; int LCD(int n, int m){ int r = n*m; if(n<m) swap(n,m); while(n%m){ int t = n%m; n = m; m = t; } return r/m; } int main() { string x1,x2; int k1,k2; while(cin>>x1>>k1>>x2>>k2){ int n = x1.length(); int m = x2.length(); if(n*k1>m*k2) cout<<"Greater"<<endl; else if(n*k1<m*k2) cout<<"Less"<<endl; else{ int i=0,j=0,k=0,r=LCD(n,m); while(k<r){ if(x1[i]>x2[j]){ cout<<"Greater"<<endl; break; }else if(x1[i]<x2[j]){ cout<<"Less"<<endl; break; }else{ i = (i+1)%n; j = (j+1)%m; k++; } } if(k==r) cout<<"Equal"<<endl; } } return 0; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String in1 = sc.next(); int k1 = sc.nextInt(); String in2 = sc.next(); int k2 = sc.nextInt(); StringBuilder sb1 = new StringBuilder(), sb2 = new StringBuilder(); for (int i=0; i!=k1; i++) { sb1.append(in1); } for (int i=0; i!=k2; i++) { sb2.append(in2); } String o1 = sb1.toString(), o2 = sb2.toString(); if (o1.length() > o2.length()) { System.out.println("Greater"); } else if (o1.length() < o2.length()) { System.out.println("Less"); } else { if (o1.compareTo(o2) > 0) { System.out.println("Greater"); } else if (o1.compareTo(o2) < 0){ System.out.println("Less"); } else { System.out.println("Equal"); } } return; } }
package main import ( "fmt" "strings" ) func main() { var a,b string var c,d int fmt.Scan(&a,&c,&b,&d) a=strings.Repeat(a,c) b=strings.Repeat(b,d) ans:="Less" if len(a)==len(b){ if a==b{ ans="Equal" }else if a>b{ ans="Greater" } }else if len(a)>len(b){ ans="Greater" } fmt.Print(ans) }
var arr=readline().split(' '); function repeat(x,y){ return new Array(parseInt(y)+1).join(x) } var one=parseInt(repeat(arr[0],arr[1])) var two=parseInt(repeat(arr[2],arr[3])); if(one==two){ console.log("Equal") }else if(one<two){ console.log("Less"); }else{ console.log("Greater") }
function repeat(x,y) { let res = '' for (let i = 0; i < y; i++) { res += x } return res } let [x1,k1,x2,k2] = readline().split(' ') // console.log(x1,k1,x2,k2) let v1 = parseInt(repeat(x1,k1)) let v2 = parseInt(repeat(x2,k2)) // console.log(v1,v2) if(v1 < v2){ console.log('Less') } else if(v1 === v2){ console.log('Equal') } else{ console.log('Greater') }
static void Main(string[] args) { string input = string.Empty; while (!string.IsNullOrEmpty(input = Console.ReadLine())) { string[] arr = input.Split(' '); string x1 = arr[0]; string k1 = arr[1]; string x2 = arr[2]; string k2 = arr[3]; string v1 = repeat(x1, int.Parse(k1)); string v2 = repeat(x2, int.Parse(k2)); if (v1 == v2) { Console.WriteLine("Equal"); } else { if (v1.Length == v2.Length) { for (int i = 0; i < v1.Length; i++) { if (v1[i] < v2[i]) { Console.WriteLine("Less"); break; } else if (v1[i] > v2[i]) { Console.WriteLine("Greater"); break; } } } else if (v1.Length < v2.Length) { Console.WriteLine("Less"); } else if (v1.Length > v2.Length) { Console.WriteLine("Greater"); } } } } static string repeat(string x, int k) { string value = string.Empty; for (int i = 0; i < k; i++) { value += x; } return value; }
#include<iostream> #include<string> using namespace std; int main() { int x1, k1, x2, k2; cin >> x1 >> k1 >> x2 >> k2; string str1 = to_string(x1); string str2 = to_string(x2); string s1 = str1, s2 = str2; for (int i = 0; i < k1 - 1; i++) s1.append(str1); for (int i = 0; i < k2 - 1; i++) s2.append(str2); if(s1.size()<s2.size()) cout<<"Less"<<endl; else if(s1.size()>s2.size()) cout<<"Greater"<<endl; else{ if(s1<s2) cout<<"Less"<<endl; else if(s1==s2) cout<<"Equal"<<endl; else cout<<"Greater"<<endl; } return 0; }
import java.util.Scanner; public clas***ain { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] strs = scanner.nextLine().split(" "); String str1 = strs[0]; int k1 = Integer.parseInt(strs[1]); String string1 = solve(str1, k1); String str2 = strs[2]; int k2 = Integer.parseInt(strs[3]); String string2 = solve(str2, k2); if (string1.length() > string2.length()){ System.out.println("Greater"); return; }else if(string1.length() < string2.length()){ System.out.println("Less"); return; }else { for (int i = 0; i < string1.length(); i++) { if (string1.charAt(i) > string2.charAt(i)){ System.out.println("Greater"); return; }else if (string1.charAt(i) < string2.charAt(i)){ System.out.println("Less"); return; } } } System.out.println("Equal"); } private static String solve(String str, int k){ StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < k; i++) { stringBuilder.append(str); } while (stringBuilder.charAt(0) == '0'){ stringBuilder.deleteCharAt(0); } return stringBuilder.toString(); } }
#include<stdio.h> int main(void) { char x1[11] = {0}, x2[11] = {0}; int k1 = 0, k2 = 0, x1_len = 0, x2_len = 0, v1 = 0, v2 =0; int i, j, k; scanf("%s%d%s%d",x1,&k1,x2,&k2); x1_len = strlen(x1); x2_len = strlen(x2); if(k1 * x1_len > k2 * x2_len) { v1 = 1; } else if(k1 * x1_len < k2 * x2_len) { v2 = 1; } else { for(i=0,j=0,k=0; k<k1*x1_len; k++) { if(x1[i] > x2[j]) { v1 = 1; break; } else if(x1[i] < x2[j]) { v2 = 1; break; } else { i++; j++; if(i >= x1_len) { i = 0; } if(j >= x2_len) { j = 0; } } } } if(v1) { printf("Greater\n"); } else if(v2) { printf("Less\n"); } else { printf("Equal\n"); } return 0; }
import java.util.*; public class Main{ public static void main(String... args){ try(Scanner in = new Scanner(System.in)){ String x1 = in.next(); int k1 = in.nextInt(); String x2 = in.next(); int k2 = in.nextInt(); String s1 = ""; String s2 = ""; for(int i = 0;i < k1;i++){ s1 +=x1; } for(int i = 0;i < k2;i++){ s2 +=x2; } System.out.println(helper(s1,s2)); } } public static String helper(String s1,String s2){ char[] ch1 = s1.toCharArray(); char[] ch2 = s2.toCharArray(); int ch1_len = ch1.length; int ch2_len = ch2.length; if(ch1_len > ch2_len){ return "Greater"; }else if(ch1_len < ch2_len) { return "Less"; }else if(ch1_len == ch2_len) { for(int i = 0;i < ch1_len;i++) { if(ch1[i] > ch2[i]) return "Greater"; else if(ch1[i] < ch2[i]) return "Less"; else continue; } } return "Equal"; } }