Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.Scanner;
- class SuperString{
- LinkedList<String> list;
- public SuperString(){
- list = new LinkedList<String>();
- }
- public void append(String s){
- list.add(s);
- }
- public void insert(String s){
- list.addFirst(s);
- }
- public boolean contains(String s){
- String sega = "";
- for(int i=0;i<list.size();i++){
- sega += list.get(i);
- }
- if(sega.contains(s)) return true;
- return false;
- }
- public String toString(){
- String sega = "";
- for(int i=0;i<list.size();i++){
- sega += list.get(i);
- }
- return sega;
- }
- public void removeLast(int k){
- if((k<10)&&(k<=list.size())){
- for(int i = 0; i<k; i++){
- list.removeLast();
- }
- }
- }
- public void reverse(){
- LinkedList<String> tmp = new LinkedList<String>();
- for(int i=list.size()-1;i>=0;i--){
- tmp.add(revercePodstring(list.get(i)));
- }
- list = tmp;
- }
- public String revercePodstring(String s){
- String nov = "";
- for(int i=s.length()-1;i>=0;i--){
- nov+= s.charAt(i);
- }
- return nov;
- }
- }
- public class SuperStringTest {
- public static void main(String[] args) {
- Scanner jin = new Scanner(System.in);
- int k = jin.nextInt();
- if ( k == 0 ) {
- SuperString s = new SuperString();
- while ( true ) {
- int command = jin.nextInt();
- if ( command == 0 ) {//append(String s)
- s.append(jin.next());
- }
- if ( command == 1 ) {//insert(String s)
- s.insert(jin.next());
- }
- if ( command == 2 ) {//contains(String s)
- System.out.println(s.contains(jin.next()));
- }
- if ( command == 3 ) {//reverse()
- s.reverse();
- }
- if ( command == 4 ) {//toString()
- System.out.println(s);
- }
- if ( command == 5 ) {//removeLast(int k)
- s.removeLast(jin.nextInt());
- }
- if ( command == 6 ) {//end
- break;
- }
- }
- }}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement