我试图解决seating arrangement的Hackerearth问题,但我无法像在C ++中那样从stdin的while循环中获取输入
#include <iostream>
using namespace std;
#define lli long long int
#define MAX(x,y) ((x) > (y) ? (x) : (y))
int main()
{
int t,s;
cin>>t; //no of test cases
int a[] = {-11,11,9,7,5,3,1,-1,-3,-5,-7,-9};// array to find opposite facing seat-number
string b[] = {"WS","WS","MS","AS","AS","MS"}; // array to find seat-type
while(t--)
{
cin>>s; // input seat no
int i = s%12;
cout<<s+a[i]<<" ";
int j = s%6;
cout<<b[j]<<"\n";
}
return 0;
}
我试图在R中复制相同的程序:
test.case <- as.integer(readline())
while(test.case>0)
{
test.case = test.case - 1
seat <- c(-11,11,9,7,5,3,1,-1,-3,-5,-7,-9)
names(seat) <- c("WS","WS","MS","AS","AS","MS","WS","WS","MS","AS","AS","MS")
seat.input <- as.integer(readline())
s <- seat.input %% 12
cat(s+seat[s],names(seat[s]))
}
任何人都可以帮助我纠正它。