标签:
题目1(必要的储存量)
题目2(统计字符1的个数)
编译器将给出警告warning: implicit declaration of function `strlen‘
修改后的程序:
1 #include <stdio.h> 2 #include <string.h> 3 #define N 65536 4 int main(void) 5 { 6 char s[N]; 7 scanf("%s", s); 8 int tot = 0, len = strlen(s); 9 for (int i = 0; i < len; i++) 10 tot += (‘1‘ == s[i]) ? 1 : 0; 11 printf("%d\n", tot); 12 return 0; 13 }
习题3-1 得分(Score)
1 #include <stdio.h> 2 #include <string.h> 3 int main(void) 4 { 5 int n; 6 char s[81]; 7 scanf("%d", &n); 8 for (int i = 0; i < n; i++) { 9 scanf("%s", s); 10 int sum = 0, flag = 0, len = strlen(s); 11 for (int j = 0; j < len; j++) { 12 flag += (s[j] == ‘O‘) ? 1 : -flag; 13 sum += (flag) ? flag : 0; 14 } 15 printf("%d\n", sum); 16 } 17 return 0; 18 }
习题3-2 分子量(Molar Mass)
标签:
原文地址:http://www.cnblogs.com/untitled/p/4570350.html