1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> char s[1001],t[1],x[1001]; int main() { gets(s); int len = strlen(s); int i; for(i=0;i<len;i++){ if (i==0&&s[i]!=' '|| i>0 && s[i]!=' ' && s[i-1]==' ') { t[0]=toupper(s[i]); strcat(x, t); } } printf("%s",x); return 0; }C++ :
#include <iostream> #include <cstring> using namespace std; char zifu(char c){ char t; if (c >= 'a' && c <= 'z'){ t = c - 32; }else if (c >= 'A' && c <= 'Z'){ t = c; } return t; } int main(){ int i; char c; char a[2000]; gets(a); for (i = 0;i < strlen(a);i++){ if (i == 0 && a[i] != ' '){ c = zifu(a[i]); cout<<c; }else if(i != 0 && a[i] != ' ' && a[i - 1] == ' '){ c = zifu(a[i]); cout<<c; } } }Pascal :
program liumohan; var i:longint; s,m:string; begin read(S); insert(' ',s,0); for i:=1 to length(S) do begin if s[i]=' ' then if (ord(s[i+1]) in [65..90]) or (ord(s[i+1]) in [97..122]) then m:=m+s[i+1]; end; writeln(upcase(m)); end.Java :
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String str=scanner.nextLine(); str=str.trim(); String[] strArray=str.split(" "); for(int i=0;i<strArray.length;i++){ if(!strArray[i].equals("")&&strArray[i]!=null){ char chr=strArray[i].charAt(0); if(chr>=97&&chr<=122){ chr=(char) (chr-32); } System.out.print(chr); } } } }Python :
str = input(); str = str.strip() li = str.split(" "); for s in li: if len(s) != 0: s = s[0].upper(); print(s,end='')
- 1
信息
- ID
- 95
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 9
- 标签
- 递交数
- 12
- 已通过
- 3
- 上传者