张昊然 • 4年前
样例:1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 55 56 58 59 60
61 62 63 64 65 66 68 69 80 81 82 83 84 85 86 88 89 90 91 92 93 94 95 96 98 99 100 101 102 103 104 105 106 108 109 110 111 112 113 114 115 116 118 119 120
121 122 123 124 125 126 128 129 130 131 132 133 134 135 136 138 139 140 141 142 143 144 145 146 148 149 150 151 152 153 154 155 156 158 159 160 161 162 163
164 165 166 168 169 170 171 172 173
给我的错误样例中170,171,172,173都带有7!!!
评论:
#include <iostream>
using namespace std;
int main() {
int n, i = 1, x, t, x2;
cin >> n;
for (i; i <= n; i++) {
if (i % 10 == 7 || i / 10 == 7) continue;
cout << i << " ";
}
return 0;
}
对于任意一个整数n(n<=100),输出1-n内所有不包含7的数,如,n=18,则7和17均不输出。(用continue实现)
其实是n的值给错了所以只判断两位就行,不用循环判断每一位
#include <iostream>
using namespace std;
int main() {
int n, i = 1, x, t, x2;
cin >> n;
for (i; i <= n; i++) {
t = i;
while (t) {
x = t % 10;
if (x == 7) break;
t /= 10;
}
if (x == 7) continue;
cout << i << " ";
}
return 0;
}
我原来全部判断就WA了
OJ的题是真有病
所以别刷OJ了
赶紧去洛谷