1 条题解
-
0
C :
#include <stdio.h> int main() { char p[3][81]; int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0; for (i = 0;i < 3;i++) { gets(p[i]); } for (i = 0;i < 3;i++) { for (j = 0;p[i][j] != '\0';j++) { if ('A' <= p[i][j] && p[i][j] <= 'Z') upper++; else if ('a' <= p[i][j] && p[i][j] <= 'z') lower++; else if ('0' <= p[i][j] && p[i][j] <= '9') digit++; else if (p[i][j] == ' ') space++; else other++; } } printf("%d %d %d %d %d\n", upper, lower, digit, space, other); return 0; }
C++ :
#include <stdio.h> int main() { char p[3][81]; int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0; for (i = 0;i < 3;i++) { gets(p[i]); } for (i = 0;i < 3;i++) { for (j = 0;p[i][j] != '\0';j++) { if ('A' <= p[i][j] && p[i][j] <= 'Z') upper++; else if ('a' <= p[i][j] && p[i][j] <= 'z') lower++; else if ('0' <= p[i][j] && p[i][j] <= '9') digit++; else if (p[i][j] == ' ') space++; else other++; } } printf("%d %d %d %d %d\n", upper, lower, digit, space, other); return 0; }
Pascal :
var i,ia,ib,ic,id,ie:longint; s,sa:string; c:char; begin s:=''; readln(sa); s:=s+sa; readln(sa); s:=s+sa; readln(sa); s:=s+sa; ia:=0; ib:=0; ic:=0; id:=0; ie:=0; for i:=1 to length(s) do begin c:=s[i]; if( c in ['A'..'Z'] ) then inc(ia) else if( c in ['a'..'z'] ) then inc(ib) else if( c in ['0'..'9'] ) then inc(ic) else if( c=' ' ) then inc(id) else inc(ie); end; writeln(ia,' ',ib,' ',ic,' ',id,' ',ie); end.
Java :
import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in) ; public static void main(String[] args) { String str = "" ; for (int i = 0; i < 3; i++) { String str1 = s.nextLine() ; str+=str1 ; } char c[] = str.toCharArray() ; int a = 0 ; int b = 0 ; int d = 0; int e = 0; int f = 0 ; for (int i = 0; i < c.length; i++) { if(c[i]<='Z'&&c[i]>='A'){ a++ ; }else if(c[i]<='z'&&c[i]>='a'){ b++ ; }else if(c[i]<='9'&&c[i]>='0'){ d++ ; }else if(c[i]==' '){ e++ ; }else f++ ; } System.out.println(a+" "+b+" "+d+" "+e+" "+f); } }
- 1
信息
- ID
- 1304
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者