#include<iostream>using namespace std;struct Tu{ char shape; double x0, y0, r; double x1, y1, x2, y2;}tu[500];int main(){ char v; int n = 0, s = 0; while (cin >> v) { if (v == '*') break; if (v == 'c') { cin >> tu[n].x0 >> tu[n].y0 >> tu[n].r; tu[n++].shape = v; continue; } if (v == 'r') { cin >> tu[n].x1 >> tu[n].y1 >> tu[n].x2 >> tu[n].y2; tu[n++].shape= v; } } for (int i = 0; i < n; i++) { if (tu[i].shape== 'r') cout << tu[i].shape <<" "<< tu[n].x1<<" " << tu[n].y1<<" " << tu[n].x2<<" " << tu[n].y2 << endl; if (tu[i].shape == 'c') cout << tu[i].shape<<" " << tu[n].x0 <<" "<< tu[n].y0<<" " <<tu[n].r<<endl; }return 0;}
1 回答
已采納

onemoo
TA貢獻(xiàn)883條經(jīng)驗 獲得超454個贊
提問時可以把問題寫得更明確些,比如為什么你覺得有問題? 你預(yù)期是什么樣的結(jié)果?
看起來這代碼大概是要依據(jù)輸入r或c來存儲矩形和圓形的信息。 是不是最后輸出的信息都是0?
在最后的for循環(huán)中,你根據(jù)shape進(jìn)行輸出時誤把索引寫成了?n,應(yīng)該是?i?才對。
還有,你定義了一個s變量,但并沒有使用。
- 1 回答
- 0 關(guān)注
- 1317 瀏覽
添加回答
舉報
0/150
提交
取消