我是靠谱客的博主 优雅红酒,这篇文章主要介绍C语言程序设计-1028 人口普查,现在分享给大家,希望可以做个参考。

妈个鸡,输出为0 的时候不能带空格!
但使用scanf("%s %d/%d/%d"…)读不到数,scanf("%s", &name)也读不到数,why?

#include <iostream>
#include <string>
using namespace std;
int main(){
	int N, year, month, day, young = 0, old = 20000000, temp, cnt = 0;
	string name, old_name, young_name;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> name;
		scanf("%d/%d/%d", &year, &month, &day);
		temp = year*365 + month*30 + day;
		if(temp >= 1814*365 + 9*30 + 6 && temp <= 2014*365 + 9*30 + 6){
			cnt++;
			if(temp > young){
				young = temp; young_name = name;
			}
			if(temp < old){
				old = temp; old_name = name;
			}
		}
	}
    if(cnt) printf("%d %s %s", cnt, old_name.c_str(), young_name.c_str());
    else cout << 0;
	return 0;
}

最后

以上就是优雅红酒最近收集整理的关于C语言程序设计-1028 人口普查的全部内容,更多相关C语言程序设计-1028内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部