标题:问一下这个代码为什么会出错
取消只看楼主
Arther0919
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2019-9-11
结帖率:100%
已结贴  问题点数:18 回复次数:0 
问一下这个代码为什么会出错
#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;

int a[6];

//one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty
//a both another first second third

int main(){
    string s;
    cin >> s;
    int count = 0;
    int j = 0, temp = 0;
    for(int i = 0; i < 6; i++){
        string s1;
        while(s[j] != ' ' || s[j] != '.'){
            j++;
        }
        for(; temp < j; temp++){
            int z = 0;
            s1[z] = s[temp];
            z++;
        }
        temp++;
        j++;

    if(s1 == "one" || s1 == "a" || s1 == "first"){
        a[count] = 1;
        count++;
    }
    else if(s1 == "two" || s1 == "second" || s1 == "both"){
        a[count] = 2;
        count++;
    }
    else if(s1 == "three" || s1 == "third" || s1 == "another"){
        a[count] = 3;
        count++;
    }
    else if(s1 == "four"){
        a[count] = 4;
        count++;
    }
    else if(s1 == "five"){
        a[count] = 5;
        count++;
    }
    else if(s1 == "six"){
        a[count] = 6;
        count++;
    }
    else if(s1 == "seven"){
        a[count] = 7;
        count++;
    }
    else if(s1 == "eight"){
        a[count] = 8;
        count++;
    }
    else if(s1 == "nine"){
        a[count] = 9;
        count++;
    }
    else if(s1 == "ten"){
        a[count] = 10;
        count++;
    }
    else if(s1 == "eleven"){
        a[count] = 11;
        count++;
    }
    else if(s1 == "twelve"){
        a[count] = 12;
        count++;
    }
    else if(s1 == "thirteen"){
        a[count] = 13;
        count++;
    }
    else if(s1 == "fourteen"){
        a[count] = 14;
        count++;
    }
    else if(s1 == "fifteen"){
        a[count] = 15;
        count++;
    }
    else if(s1 == "sixteen"){
        a[count] = 16;
        count++;
    }
    else if(s1 == "seventeen"){
        a[count] = 17;
        count++;
    }
    else if(s1 == "eighteen"){
        a[count] = 18;
        count++;
    }
    else if(s1 == "nineteen"){
        a[count] = 19;
        count++;
    }
    else if(s1 == "twenty"){
        a[count] = 20;
        count++;
    }}
    for(int i = 0; i < count; i++){
        a[i] = a[i]*a[i];
        a[i] %= 100;
    }
   
    sort(a, a+count);

    for(int i = 0; i < count; i++){
        if(a[i] == 0)   continue;
        cout << a[i];
    }
    return 0;
}
搜索更多相关主题的帖子: int count for || temp 
2020-01-15 11:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-498933-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.635230 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved