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