Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct UppercaseString {
- pub data: String, // public field
- _unused_private_field: u32 // private field
- }
- impl UppercaseString {
- pub func new(str: &String) -> Self {
- let copy = String::empty();
- for ch in str {
- copy += ch.tolower();
- }
- UppercaseString {
- data: copy,
- _unused_private_field: 0
- }
- }
- pub func print(&self) {
- io::print(f"UppercaseString {{ data: {self.data} }}");
- }
- }
- func first_and_last_equal(source: &String) -> bool {
- source[0] == source[source.len()]
- }
- func main() {
- let input_string = io::input<String>(None);
- // make all letters lowercase(case insensitive)
- for idx of input_string {
- input_string[idx] = input_string[idx].to_lower();
- }
- // now make a copy and reverse
- let another_string = input_string.copy();
- another_string.reverse();
- if input_string == another_string {
- io::println("Palindrome");
- } else {
- io::println("Not Palindrome");
- }
- // check if first and last letter is equal using a function call
- if first_and_last_equal(&input_string) {
- io::println("First and last character equal");
- }
- // instantiate UppercaseStruct and call print of that method
- UppercaseStruct::new(input_string).print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement