| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1704 人关注过本帖
标题:问一下这个代码为什么会出错
只看楼主 加入收藏
Arther0919
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2019-9-11
结帖率:100%
收藏
已结贴  问题点数:18 回复次数:3 
问一下这个代码为什么会出错
#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
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:7 
这个代码为什么会出错
说出是什么错误
    a. 编译和链接错误,那么应当贴出编译器给出的错误信息
    b. 运行结果不符合你的预期,那应该贴出你的输入数据实际输出数据你期待的输出数据

2020-01-15 11:56
外部三电铃
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:那一年
等 级:贵宾
威 望:57
帖 子:2012
专家分:7306
注 册:2007-12-17
收藏
得分:7 
自己先把错误贴出来啊,不要让大家猜😴

那一年,苍井空还是处女
2020-01-15 12:10
quanhuang55
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-1-7
收藏
得分:0 
新手上膛!
2020-01-15 15:40
快速回复:问一下这个代码为什么会出错
数据加载中...
 
   



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

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