一、题目链接
http://noi.openjudge.cn/ch0107/18/
二、解题思路(Java)
三、解题思路(C++)
四、Java程序
import java.util.Scanner;
public class Main {
public String subStringInfo(String s1, String s2) {
if (s2.contains(s1)) {
return s1 + " is substring of " + s2;
}
else if (s1.contains(s2)) {
return s2 + " is substring of " + s1;
}
else {
return "No substring";
}
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
String s1 = input.next();
String s2 = input.next();
System.out.print(test.subStringInfo(s1, s2));
}
}
五、C++程序
#include <iostream>
using namespace std;
int main()
{
string one;
string two;
getline(cin, one);
getline(cin, two);
if (one.find(two) != one.npos)
{
cout << two << " is substring of " << one;
}
else if (two.find(one) != two.npos)
{
cout << one << " is substring of " << two;
}
else
{
cout << "No substring";
}
return 0;
}