sgu 302
来源:互联网 发布:mac重装系统 编辑:程序博客网 时间:2024/05/22 17:03
#include <stdio.h>#include <string.h>void putUpper(char c) { if (c >= 'a') { //c is lowercase putchar(c - 32); } else { putchar(c); }}void putLower(char c) { if (c <= 'Z') { // c is Uppercase putchar(c + 32); } else { putchar(c); }}int main() { char s[1009]; char f[1009]; int k = 0; // f and k as stack, the last one is the nearest tag int i = 0; s[0] = '\0'; scanf("%s", s); while (s[i] != '\0') { if (s[i] == '<') { // si is a tag ++i; if (s[i] == '/'){ //si is the right tag, pop stack --k; } else { //si is the left tag, push stack ++k; f[k] = s[i]; } while (s[i] != '>') ++i; //i went to the end of tags } else { if (k == 0) { //si is not betwwen tag putchar(s[i]); } else if (f[k] == 'D') { //si si between DOWN tag putLower(s[i]); } else { //si is between UP tag putUpper(s[i]); } } ++i; } return 0;}