标签:color 存在 sed 字符 nbsp 思路 cst cli open
C. Divisibility by Eight
题意:给出一串数字字符串,问能否去掉一些位置的数字字符使得剩下的数字字符形成的数能被8整除?
思路:只需存在一个3位数,其能被8整除即可(8*125=1000)。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 char s[110]; 6 7 int main() 8 { 9 scanf("%s", s); 10 int len = strlen(s); 11 bool flag = false; 12 for (int i = 0;!flag&& i < len; i++) 13 { 14 int ret = s[i] - ‘0‘; 15 if (ret % 8 == 0) 16 { 17 printf("YES\n%d\n", ret); 18 flag = true; 19 break; 20 } 21 for (int j = i + 1;!flag&& j < len; j++) 22 { 23 int ret2 = ret * 10 + s[j] - ‘0‘; 24 if (ret2 % 8 == 0) 25 { 26 printf("YES\n%d\n", ret2); 27 flag = true; 28 break; 29 } 30 for (int k = j + 1; !flag&& k < len; k++) 31 { 32 int ret3 = ret2 * 10 + s[k] - ‘0‘; 33 if (ret3 % 8 == 0) 34 { 35 printf("YES\n%d\n", ret3); 36 flag = true; 37 break; 38 } 39 } 40 } 41 } 42 if (!flag) printf("NO\n"); 43 return 0; 44 }
Codeforces Round #306 (Div. 2)
标签:color 存在 sed 字符 nbsp 思路 cst cli open
原文地址:https://www.cnblogs.com/ivan-count/p/8890422.html