题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5095
几个坑
系数为正负1是不输出系数(比赛时wa到死)
0时不输出但全零时要输出0
加号和减号的控制
#include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #include <stack> #include <vector> #include <queue> #include <map> #include <set> using namespace std; const int maxn = 110; int a[maxn]; const char ch[] = "pqruvwxyz"; int main() { //freopen("in.txt", "r", stdin); int T; scanf("%d", &T); while(T--) { for(int i = 0; i < 10; i++) scanf("%d", &a[i]); bool flag = false; for(int i = 0; i < 9; i++) { if(a[i] > 0) { if(flag) printf("+"); if(a[i] == 1) printf("%c", ch[i]); else printf("%d%c", a[i], ch[i]); flag = true; } else if(a[i] < 0) { if(a[i] == -1) printf("-%c", ch[i]); else printf("%d%c", a[i], ch[i]); flag = true; } } if(!flag) { printf("%d", a[9]); } else { if(a[9] > 0) printf("+%d", a[9]); else if(a[9] < 0) printf("%d", a[9]); } printf("\n"); } return 0; }
时间: 2024-12-29 11:16:17