problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1053 命名空间参考

1053 住房空置率 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1053, case1)
 

详细描述

1053 住房空置率

函数说明

◆ main()

int pat::b::b1053::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp1802 行定义.

1802 {
1803 int n;
1804 double e;
1805 int d;
1806 int cnt1 = 0;
1807 int cnt2 = 0;
1808 cin >> n >> e >> d;
1809 for(int i = 0; i < n; ++i) {
1810 int k;
1811 cin >> k;
1812 int cnt = 0;
1813 for(int j = 0; j < k; ++j) {
1814 double E;
1815 cin >> E;
1816 if(E < e) {
1817 cnt++;
1818 }
1819 }
1820 if(2 * cnt > k) {
1821 if(k > d) {
1822 cnt2++;
1823 } else {
1824 cnt1++;
1825 }
1826 }
1827 }
1828 const double ans1 = static_cast<double>(cnt1) / n * 100;
1829 const double ans2 = static_cast<double>(cnt2) / n * 100;
1830 cout << fixed << setprecision(1) << ans1 << "% " << fixed << setprecision(1) << ans2 << '%';
1831 return 0;
1832 }

被这些函数引用 TEST().

◆ TEST()

pat::b::b1053::TEST ( b1053  ,
case1   
)

在文件 pat_test.cpp795 行定义.

795 {
796 istringstream in("5 0.5 10\n"
797 "6 0.3 0.4 0.5 0.2 0.8 0.6\n"
798 "10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5\n"
799 "5 0.4 0.3 0.5 0.1 0.7\n"
800 "11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n"
801 "11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1");
802 auto out = ostringstream();
803 main(in, out);
804 const auto ans = out.str();
805 ASSERT_EQ("40.0% 20.0%", out.str());
806 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().