I am trying to read the following input from user where the input looks like :
3
5 斤 2 两
7 斤 3 两
6 斤
to solve this question : https://uva.onlinejudge.org/external/125/12555.pdf
However, I have no success so far. I have googled a lot, but I am not able to put it together and I get wrong inputs everytime. Moreover, I am not sure if I am passing the inputs correctly as whether the console supports Unicode or not, which again is an overhead for me, as I am already not confident about my Unicode usage. Please help.
I tried this :
int main()
{
int t,a,b;
wchar_t ignore;
float res;
cin >> t; //number of test cases
for(int k=1;k<=t;k++)
{
a=b=0;
cin >> a;
wcin >> ignore;
if(cin.peek() != '\n')
{
cin >> b;
wcin >> ignore;
}
cout << "a : " << a << " b : " << b << endl;
}
return 0;
}
My output :
a : 5 b : 0
a : 0 b : 0
a : 0 b : 0
EDIT I tried a little variation as well, but still wrong inputs :
int main()
{
int t,a,b;
wchar_t ignore;
float res;
wcin >> t; //number of test cases
cout << t << endl;
for(int k=1;k<=t;k++)
{
a=b=0;
wcin >> a;
wcin >> ignore;
if(wcin.peek() != '\n')
{
wcin >> b;
wcin >> ignore;
}
cout << "a : " << a << " b : " << b << endl;
}
return 0;
}
EDIT2 This worked for me on a Ubuntu machine, but the online judge is still rejecting my solution. Also on my Windows bash, I am still getting the wrong output:
#include <iostream>
#include <locale>
#include <clocale>
using namespace std;
int main()
{
int t,a,b;
wchar_t ignore;
std::locale loc ("");
std::locale::global (loc);
std::setlocale(LC_ALL, NULL);
std::setlocale(LC_ALL, "");
wcin.imbue (loc);
wcin >> t; //number of test cases
for(int k=1;k<=t;k++)
{
a=b=0;
wcin >> a;
wcin >> ignore;
if(wcin.peek() != L'\n')
{
wcin >> b;
wcin >> ignore;
}
cout << "Case " << k << ": " << a*0.5+b*0.05 << endl;
}
return 0;
}