如何显示用户花费的号码,即用户输入了多少时间

how to show the number taken by user that how much time it is entered by user

本文关键字:用户 号码 输入 时间 多少 何显示 显示      更新时间:2023-10-16

>好的,该程序在使用循环时似乎很容易,但是如果还有其他条件可以做到这一点呢我已经尝试过,这是我的努力,但完全失败了。

#include<iostream>
#include<conio.h>
int main(){
    using namespace std;
    int a,b,c,d,e,f,g,h,j,k,l;
    int c1=0;
    int c2=0;
    int c3=0;
    int c4=0;
    cout<<"please enter first numbern";
    cin>>a;
    cout<<"please enter second numbern";
    cin>>b;
    cout<<"please enter third numbern";
    cin>>c;
    cout<<"please enter fourth numbern";
    cin>>d;
    cout<<"please enter fifth numbern";
    cin>>e;
    cout<<"please enter sixth numbern";
    cin>>f;
    cout<<"please enter seventh numbern";
    cin>>g;
    cout<<"please enter eighth numbern";
    cin>>h;
    cout<<"please enter ninth numbern";
    cin>>j;
    cout<<"please enter tenth numbern";
    cin>>k;
    cout<<"please enter eleventh numbern";
    cin>>l;
    if(a==1)
    {
        c1=a+1;
    }
    else if (a==1 && b==1)
    {
        c2=a+b;
    }
    else if (a==1 && b==1 && c==1)
    {
        c3=a+b+c;
    }
    else if (a==4)
    {
        c4=a+1;
    }
    cout<<"no of 1's="<<c1;
getch();
}

我正在取值,取值后我想显示 1 出现多少时间

使用循环输入N数字。当你阅读它们时(当然要确保检查错误(,计算你得到数字 1 的次数。

要计算字母变量中有多少个ones,您可以这样做:

int c1=0;
if(a==1)
{
    c1++;
}
if (b==1)
{
    c1++;
}
    ...
if (l==1)
{
    c1++;
}
cout<<"no of 1's="<<c1;
#include<iostream>
#include<conio.h>
#include <array>
#include <unordered_map>
int main(){
    using namespace std;
    static const int cCount = 11;
    array<int, cCount> values;
    static const array<std::string, cCount> numbers = {
      "first",
      "second",

      "eleventh"}; 
    for (int = 0; i < cCount; ++i) {
      cout<<"please enter " << numbers[i] << " numbern";
      cin>> values[i];
    }  

    unordered_map<int, int> counts;
    for (int = 0; i < cCount; ++i) {
      ++counts[values[i]];
    }
    cout << "no of 1's=" << counts[1];
    getch();
}

哇,真是一团糟。

使用哈希表,键是用户

输入,值是无符号的(此无符号将跟踪用户使用相应键输入值的次数(。每当用户输入值时,请递增该键处的值。然后,在最后,返回存储在键 == '1' 的值。