CodeEval Easy Level Challenge Lowercase

CodeEval Easy Level Challenge Lowercase:

Click here to go to this problem.

Description:

For this problem we just need to change upper case letters to lower case. Here i have solved this problem in 4 programming languages c, c++, java, python.


 C:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

#include <stdio.h>
int main(int argc, const char * argv[]) {
    FILE *file = fopen(argv[1], "r");
    char line[1024];
    while (fgets(line, 1024, file)) {
        for(register unsigned int i=0; line[i]; ++i){
            if(line[i] >= 'A' && line[i]<='Z') printf("%c", line[i]+32);
            else printf("%c", line[i]);
        }
        printf("\n");
    }
    return 0;
} 

Java:
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */

import java.io.*;
public class Main {
    public static void main (String[] args) throws IOException {
        File file = new File(args[0]);
        BufferedReader buffer = new BufferedReader(new FileReader(file));
        String line;
        while ((line = buffer.readLine()) != null) {
            line = line.trim();
            // Instead of changing case one by one in for loop, we can also change case of whole string in one function call
            /* System.out.println(line.toLowerCase()); */
            for(int i=0; i<line.length(); ++i){
                char c = line.charAt(i);
                if(Character.isUpperCase(c)) System.out.print(Character.toLowerCase(c));
                else System.out.print(c);
            }
            System.out.println();
        }
    }
}

Python (Python 3):
#
# Author: Quickgrid ( Asif Ahmed )
# Site: https://quickgrid.wordpress.com
#

import sys
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
    print(test.lower())

test_cases.close()

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s