1 条题解
-
0
C :
char tongji(str0,b) char str0[100]; int b[4]; {int i; for(i=0;str0[i]!='\0';i++) {if(str0[i]>=65&&str0[i]<=90||str0[i]>=97&&str0[i]<=122) b[0]++; else if(str0[i]>=48&&str0[i]<=57) b[1]++; else if(str0[i]==32) b[2]++; else b[3]++;} } int main() {char str1[100];static int i,a[4]; gets(str1); tongji(str1,a); for(i=0;i<4;i++) printf("%d ",a[i]);printf("\n"); return 0; }C++ :
#include <iostream> //#include <stdio.h> //#include <conio.h> #include <string> //#include <math.h> using namespace std; int main() { string k; getline(cin,k); int i = 0; int a = 0; int b = 0; int c = 0; int d = 0; for (; i<k.length() ; i++) { if (isalpha(k.at(i))) { a++; } else if (isdigit(k.at(i))) { b++; } else if (k.at(i) == ' ') { c++; } else { d++; } } cout << a << " " << b << " " << c << " " << d; //_getch(); return 0; }Java :
import java.util.Scanner; public class Main { /** * @param args */ static int cSum = 0,nSum = 0,sSum = 0,oSum = 0; public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); String s = input.nextLine(); Sum(s); System.out.println(cSum + " " + nSum + " " + sSum + " " + oSum + " "); input.close(); } public static void Sum(String s){ for(int i = 0; i < s.length(); i ++){ if(s.charAt(i) > 47 && s.charAt(i) < 58){ nSum ++; }else if((s.charAt(i) > 64 && s.charAt(i) < 91) ||(s.charAt(i) > 96 && s.charAt(i) < 123)){ cSum ++; }else if(s.charAt(i) == 32){ sSum ++; }else{ oSum ++; } } } }Python :
a = raw_input() #b = a[1] #c = a[2] #a = a[0] import re p = re.compile('[A-Za-z]') l = re.findall(p,a) zm = len(l) p = re.compile('[0-9]') sz = len(re.findall(p,a)) p = re.compile('[ ]') kg = len(re.findall(p,a)) print "%d %d %d %d " %(zm ,sz,kg,len(a)-zm-sz-kg)
- 1
信息
- ID
- 2019
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者