zoukankan      html  css  js  c++  java
  • 洛谷 题解 P5015 【标题统计】 NOIP2018 普及组 T1

    没有人用 scanf("%c", &ch) != EOF 吗? scanfEOF 会伤心的。

    思路:逐个读入字符,遇到EOF中止,对于每个读入的字符进行判断。

    附上考场代码:

    #include <stdio.h>
    #define file_in(f) freopen(f".in", "r", stdin)
    #define file_out(f) freopen(f".out", "w", stdout)
    #define file(f) file_in(f), file_out(f)
    
    char tmp;
    
    bool Daxie(char c)
    {
    	return (c <= 'Z') && (c >= 'A');
    }
    bool Xiaoxie(char c)
    {
    	return (c <= 'z') && (c >= 'a');
    }
    bool Number(char c)
    {
    	return (c <= '9') && (c >= '0');
    }
    bool isOK(char ch)
    {
    	return Daxie(ch) || Xiaoxie(ch) || Number(ch);
    }
    
    int main()
    {
    // 	file("title");
    	int ans = 0;
    	while (scanf("%c", &tmp) != EOF) {
    		if (isOK(tmp)) ans++;
    	}
    	printf("%d", ans);
    	return 0;
    }
    
    

    To: 不太理解的

    scanf 如果读入不到内容则会返回 -1 , 即 EOF 。 这里因为是文件读入,所以必然在文件尾处返回 EOF

  • 相关阅读:
    I
    H
    G
    F
    E
    论js里面的for循环
    js常见问题之为什么点击弹出的i总是最后一个
    array类型的方法
    string类型的方法
    for in在对象和数组中的应用
  • 原文地址:https://www.cnblogs.com/hkxadpall/p/9991864.html
Copyright © 2011-2022 走看看