C語言模擬考|lower cases

Description

Input a string which contains (a,b,c,...,z,A,B,C,...Z,\t and space ' ') and end of '\n',Please convert all the character into lower case and delete all the space and \t.(1 <= string length <= 20)

Sample Input

I L o  Ve       YoU

Sample Output

iloveyou

HINT

The input "I L o Ve YoU" means that:

I+' '+L+' '+o+' '+' '+V+e+'\t'+Y+o+U


#include <stdio.h>
#include <string.h>

int main() {
	char array[1000000];
	gets(array);
	printf(array);
	printf("\n");
	
	int i, n = strlen(array), dif = 'a' - 'A';
	for (i = 0; i < n; ++ i) {
		if (array[i] == ' ' || array[i] == '\t') continue;
		if (array[i] >= 'A' && array[i] <= 'Z') {
			array[i] += dif;
		}
		printf("%c",array[i]);
	}
} 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章