首页 > 代码库 > hihocoder 1197 Give My Text Back
hihocoder 1197 Give My Text Back
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <iostream> 4 #include <string.h> 5 #include <limits.h> 6 #include <queue> 7 #include <vector> 8 #include <set> 9 #include <map> 10 #include <algorithm> 11 12 using namespace std; 13 14 15 char buf[10000]; 16 17 bool iszimu(char c) { 18 return ((c>=‘a‘ && c<=‘z‘) || (c>=‘A‘ && c<=‘Z‘)); 19 } 20 char turn_capital(char c) { 21 if (c>=‘a‘ && c<=‘z‘) { 22 c = c + ‘A‘ - ‘a‘; 23 } 24 return c; 25 } 26 char turn_small(char c) { 27 if (c>=‘A‘ && c<=‘Z‘) c = c+‘a‘-‘A‘; 28 return c; 29 } 30 int main() 31 { 32 while(scanf("%[^\n]", buf)>0){ 33 //printf("%s\n", buf); 34 char str[10000] = {0}; 35 int j = 0; 36 for (int i=0;buf[i]!=0;++i) { 37 if (iszimu(buf[i])) { 38 if (j==0 || str[j-2] == ‘.‘) { 39 str[j] = turn_capital(buf[i]); 40 } else { 41 str[j] = turn_small(buf[i]); 42 } 43 } else if (buf[i] == ‘ ‘) { 44 if (j==0) continue; 45 if (str[j-1] != ‘ ‘) str[j] = buf[i]; 46 else j--; 47 } else if (buf[i] == ‘,‘ || buf[i] == ‘.‘) { 48 if (str[j-1] == ‘ ‘) { 49 str[j-1] = buf[i]; 50 str[j] = ‘ ‘; 51 } else { 52 str[j] = buf[i]; 53 str[j+1] = ‘ ‘; 54 j++; 55 } 56 } 57 j++; 58 } 59 printf("%s\n", str); 60 getchar(); 61 } 62 }
hihocoder 1197 Give My Text Back
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。