1 条题解
-
0
C :
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char c; int e; int b; int a; int d; e=0; b=0; a=0; d=0; while((c=getchar())!='\n') { if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) e++; else if(c>='0'&&c<='9') b++; else if(c==' ') a++; else d++; } printf("%d %d %d %d\n",e,a,b,d); return 0; }
C++ :
#include <stdio.h> #include <math.h> int main() { char c; int letter, space, digit, other; letter = 0; space = 0; digit = 0; other = 0; while ((c = getchar()) != '\n') { if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) letter++; else if (c == ' ') space++; else if ('0' <= c && c <= '9') digit++; else other++; } printf("%d %d %d %d\n", letter, space, digit, other); return 0; }
Pascal :
var i,ia,ib,ic,id:longint; s:string; c:char; begin readln(s); ia:=0; ib:=0; ic:=0; id:=0; for i:=1 to length(s) do begin c:=upcase(s[i]); if( c in ['A'..'Z'] ) then inc(ia) else if( c=' ' ) then inc(ib) else if( c in ['0'..'9'] ) then inc(ic) else inc(id); end; writeln(ia,' ',ib,' ',ic,' ',id); end.
Java :
import java.util.*; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int a=0,b=0,c=0,d=0; String s = cin.nextLine(); char[] ch= s.toCharArray(); for(int i=0;i<ch.length;i++){ if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z')) a++; else if(ch[i]==' ') b++; else if(ch[i]>='0'&&ch[i]<='9') c++; else d++; } System.out.printf("%d %d %d %d\n", a,b,c,d); } }
Python :
c1 = c2 = c3 = c4 = 0 for i in raw_input(): if i.isalpha(): c1 = c1 + 1 elif i.isspace(): c2 = c2 + 1 elif i.isdigit(): c3 = c3 + 1 else: c4 = c4 + 1 print c1,c2,c3,c4
- 1
信息
- ID
- 1275
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者