标签:cin c++ 顺序 bre define iostream 算法入门 number numbers
算法入门经典 P57
把前n(n<=100000)个整数顺序写在一起,123456789...数一数0-9各出现多少次。
#include<stdio.h>
#include<string.h>
#include "stdafx.h"
#include "iostream"
#include <string>
#define maxn 10
int main() {
std::cout << "Please enter numbers:" << std::endl;
std::string s;
std::cin >> s;
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0;
for (int n = 0; n < s.size(); n++) {
switch (s[n]) {
case ‘0‘: a++; break;
case ‘1‘: b++; break;
case ‘2‘: c++; break;
case ‘3‘: d++; break;
case ‘4‘: e++; break;
case ‘5‘: f++; break;
case ‘6‘: g++; break;
case ‘7‘: h++; break;
case ‘8‘: i++; break;
case ‘9‘: j++; break;
}
}
std::cout << s << std::endl;
std::cout << a << b << c << d << e << f << g << h << i << j << std::endl;
}
标签:cin c++ 顺序 bre define iostream 算法入门 number numbers
原文地址:https://www.cnblogs.com/NK-007/p/9235269.html