只有通过了55% ,求解 #include<iostream> #include<string> #include<vector> #include<stdio.h> #include<string.h> #include<map> #include<algorithm> #include<queue> #include<fstream> using namespace std; int n; string num; int nums[20]; int vis[11]; int BigNumMod(int BigNum[], int c, int length) { int ans = 0; for (int i = 0; i < length; i++) ans = ((ans * 10) + BigNum[i]) % c; return ans; } int main() { scanf("%d", &n); int len, cnt, c; while (n--) { cin >> num; cnt = 0; len = num.length(); memset(vis, -1, sizeof(vis)); vis[0] = 1; for (int i = 0; i < len; i++)nums[i] = num[i] - '0'; for (int i = 0; i < len; i++) { c = num[i] - '0'; if (vis[c] == 1)cnt++; else if (vis[c] == -1 && BigNumMod(nums, c, len) == 0) { vis[c] = 1; cnt++; } else { vis[c] = 0; } } printf("%s", len == cnt ? "G" : cnt == 0 ? "S" : "H"); if (n != 0)printf("\n"); } return 0; }
点赞 评论

相关推荐

牛客网
牛客企业服务