一、题目链接
http://noi.openjudge.cn/ch0107/16/
二、解题思路(Java)
三、解题思路(C++)
四、Java程序
import java.util.Scanner;
public class Main {
public char compare(String one, String two) {
one = one.toLowerCase();
two = two.toLowerCase();
if (one.compareTo(two) < 0) {
return '<';
}
else if (one.compareTo(two) > 0) {
return '>';
}
else {
return '=';
}
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
String one = input.nextLine();
String two = input.nextLine();
System.out.print(test.compare(one, two));
}
}
五、C++程序
#include <iostream>
using namespace std;
int main()
{
string one;
string two;
getline(cin, one);
getline(cin, two);
int m = one.length();
int n = two.length();
int i;
for (i = 0; i < m; i++)
{
if (isupper(one[i]))
{
one[i] = tolower(one[i]);
}
}
for (i = 0; i < n; i++)
{
if (isupper(two[i]))
{
two[i] = tolower(two[i]);
}
}
if (one.compare(two) < 0)
{
cout << '<';
}
else if (one.compare(two) > 0)
{
cout << '>';
}
else
{
cout << '=';
}
return 0;
}